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 ...
随机推荐
- 【转】ASP.NET MVC 数据验证及相关内容
原文地址:http://www.jb51.net/article/56713.htm 一.数据验证 数据验证的步骤在模型类中添加与验证相关的特性标记在客户端导入与验证相关的js文件和css文件使用与验 ...
- lesson4:使用锁Lock来解决重复下单的问题
demo源码:https://github.com/mantuliu/javaAdvance 中的类Lesson4IndependentLock 在上一节中,我们分析了Lock的源代码并一起实践了粗粒 ...
- Ios17个常用代码整理
.判断邮箱格式是否正确的代码 //利用正则表达式验证 -(BOOL)isValidateEmail:(NSString *)email { NSString *emailRegex = @" ...
- 573 The Snail(蜗牛)
The Snail A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can ...
- 学做酷炫有爱的免费网页,学习 Github Page 教你分分钟搭建自己的博客
Github Page 网页搭建教程,教你分分钟搭建自己的博客 很多其它美丽的网页搭建教程教程.请看这里:http://www.duobei.com/course/8506331668 waterma ...
- HDFS集群balance(4)-- 测试计划
转载请注明博客地址:http://blog.csdn.net/suileisl HDFS集群balance,对应版本balance design 6 如需word版本,请QQ522173163联系索要 ...
- 怎样将关系型数据表转换至hbase数据表
首先须要把关系型数据库的数据表的数据添加由 "纵向延伸",转变为HBase数据表的"横向延伸" 一.Hbase的存储结构 a) HBase以表(HTa ...
- Linux查看代码量
利用find xargs wc可方便的计算出某个目录下源文件的代码量find sourcecode_dir_path -type f -name "*.c" -print0 | ...
- EventBus 事件总线 案例
简介 地址:https://github.com/greenrobot/EventBus EventBus是一个[发布 / 订阅]的事件总线.简单点说,就是两人[约定]好怎么通信,一人发布消息,另外一 ...
- struts2获取request、session、application
struts2获取request.session.application public class LoginAction extends ActionSupport implements Reque ...