ASP.NET Email + WebConfig
这里演示如果把 Email provider 的资料写在 WebConfig 里和调用它.
如果整个项目只需要使用一个 Email, 可以写入system.net里, 微软已经帮我们设计好了
<configuration>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="Stooges Web Design Default <stooges@stooges.com.my>">
<network host="mail.stooges.com.my"
port=""
userName="stooges@stooges.com.my"
password="password"
enableSsl="false" />
</smtp>
</mailSettings>
</system.net>
<configuration>
然后简单调用就可以了
SmtpClient smtp = new SmtpClient();
MailMessage mail = new MailMessage
{
Subject = "subject",
Body = "html content",
IsBodyHtml = true
};
mail.To.Add("hengkeat87@gmail.com");
smtp.Send(mail);
如果有多个Email要使用,我们就得自己写webconfig然后掉用了 :
读 webconfig 资料可以参考: http://www.cnblogs.com/keatkeat/p/5404128.html
<configuration>
<configSections>
<sectionGroup name="mailSettings">
<section name="stooges" type="System.Net.Configuration.SmtpSection"/>
</sectionGroup>
</configSections>
<mailSettings>
<stooges deliveryMethod="Network" from="Stooges Web Design<stooges@stooges.com.my>">
<network host="mail.stooges.com.my"
port=""
userName="stooges@stooges.com.my"
password="password"
enableSsl="false" />
</stooges>
</mailSettings>
</configuration> SmtpClient smtp = new SmtpClient();
SmtpSection smtpSection = (SmtpSection)ConfigurationManager.GetSection("mailSettings/stooges");
SmtpNetworkElement network = smtpSection.Network;
smtp.Host = network.Host;
smtp.Port = network.Port;
smtp.EnableSsl = network.EnableSsl;
smtp.UseDefaultCredentials = network.DefaultCredentials;
smtp.Credentials = new NetworkCredential(network.UserName, network.Password);
string from = smtpSection.From; //Stooges Web Design<stooges@stooges.com.my>
int ipos = from.IndexOf("<");
string displayName = from.Substring(, ipos);
string email = from.Substring(ipos + , from.Length - displayName.Length - );
MailMessage mail = new MailMessage
{
From = new MailAddress(email, displayName),
Subject = "subject",
Body = "html content",
IsBodyHtml = true
};
mail.To.Add("hengkeat87@gmail.com");
smtp.Send(mail);
ASP.NET Email + WebConfig的更多相关文章
- [置顶] c# asp.net 修改webconfig文件 配置
c# asp.net 修改webconfig文件 配置 #region 修改config文件 /// <summary> /// 修改config文件(AppSetting节点) /// ...
- ASP.NET的WebConfig
转:http://blog.csdn.net/q3498233/article/details/8137364 WebConfig 花了点时间整理了一下ASP.NET Web.config配置文件的基 ...
- asp.net mvc webconfig配置文件操作
读取web.config数据,可以不用编译.如发布后,非常有用web.config文件<configuration> <appSettings> <add key=&qu ...
- asp.net webApi webconfig配置常见问题
问题描述 一个项目引用不同版本的同一dll,会引发以下报错: 未能加载文件或程序集“xxx, Version=x.x.x.x, Culture=neutral, PublicKeyToken=xxxx ...
- c# asp.net 修改webconfig文件 配置
#region 修改config文件 /// <summary> /// 修改config文件(AppSetting节点) /// </summary> /// <par ...
- 再探ASP.NET 5(转载)
就在最近一段时间,微软又有大动作了,在IDE方面除了给我们发布了Viausl Studio 2013 社区版还发布了全新的Visual Studio 2015 Preview. Visual Stud ...
- [转]asp.net使用uploadify上传出现的IO Error问题
原文链接:http://blog.csdn.net/w3031213101/article/details/6335878 解决方法:1.uploadify控件的自定义size必须调整大小,即属性:s ...
- DIV+CSS+JS基础+正则表达式
...............HTML系列.................... DIV元素是用来为HTML文档内大块(block-level)的内容提供结构和背景的元素.DIV的起始 ...
- ERP反馈信息管理(十九)
前台显示的界面: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Custo ...
随机推荐
- How to Create Custom Filters in AngularJs
http://www.codeproject.com/Tips/829025/How-to-Create-Custom-Filters-in-AngularJs Introduction Filter ...
- NSString去掉火车和空格
// backString = [backString stringByReplacingOccurrencesOfString:@"\r" withString:@&quo ...
- SAX PULL解析实例
XML三种解析方式: SAX解析:基于事件驱动,事件机制基于回调函数的,得到节点和节点之间内容时也会回调事件 PULL解析:相同基于事件驱动,仅仅只是回调时是常量 DOM解析:是先把XML文件装入内存 ...
- HDFS集群balance(3)-- 架构细节
转载请注明博客地址:http://blog.csdn.net/suileisl HDFS集群balance,对应版本balance design 6 如需word版本,请QQ522173163联系索要 ...
- LSI MegaCli 命令使用2
#/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aALL 查raid级别#/opt/MegaRAID/MegaCli/MegaCli64 -AdpAll ...
- Environment Configuration Files
Environment Configuration Files When a user logs in, an environment is created for that user automat ...
- /dev/null 文件
/dev/null 文件 如果希望执行某个命令,但又不希望在屏幕上显示输出结果,那么可以将输出重定向到 /dev/null: $ command > /dev/null /dev/null 是一 ...
- 配置keil MDK和keil C51共存
配置keil MDK和keil C51共存:1.首先安装keilMDK或者安装KeilC51其中一个:2.安装到D:\keil路径下,按照默认的配置安装,完成:3.使用管理员身份打开安装好的软件,打开 ...
- 【Asp.Net】后台生成控件并绑定事件
在Asp.Net的Web页面处理流程中,有时候我们会碰到需要动态生成的控件,并为之绑定相应的事件. 接下来我们来动态的生成一个控件 //在用户代码初始化阶段添加控件 protected void Pa ...
- Javascript 追本溯源
一直以来对Javascript的继承关系都是通过死记硬背下来的,对于一个理科生,喜欢逻辑思维的人来讲,死记硬背特别头痛,且理科生对于能够死记硬背下来的东西也很容易忘记,不知道其他理科生童鞋们是否如此, ...