Asp.net 自动发送邮件的方法
Asp.net 自动发送邮件的方法
今天有一个模块需要自动发送邮件的功能,就随便写了一个,记录一下作为积累。
一、首先需要配置web.config文件:
<system.net>
<mailSettings>
<smtp from="Emailname">
<network host="smtp.163.com" userName="Emailname" password="Emailpassword"
port="25" defaultCredentials="false"/>
</smtp>
</mailSettings>
</system.net>
二、然后编写发送邮件的函数:
//// <summary>
/// 邮件发送方法(带附件)
/// </summary>
/// <param name="mailto">收件人地址。如:receiver@163.com</param>
/// <param name="mailsubject">邮件标题</param>
/// <param name="mailbody">邮件正文</param>
/// <param name="mailfrom">邮件发送人地址。如:sender@163.com</param>
/// <param name="list">附件路径</param>
/// <returns></returns>
public bool MySendMail(string mailto, string mailsubject, string mailbody, string mailfrom, ArrayList list)
{
try
{
//邮件发送人地址
System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress(mailfrom);
//如test@163.com,初步测试,用test@sina.com不行,用163的邮件服务器,就必须用163邮箱的用户名
//收件人地址
System.Net.Mail.MailAddress to = new System.Net.Mail.MailAddress(mailto);//如test@tom.com
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(from, to);
mail.Subject = mailsubject;
mail.Body = mailbody;
//以下设置服务器
System.Net.Mail.SmtpClient mySmth = new System.Net.Mail.SmtpClient();
//以下为增加附件
int count = list.Count;
for (int i = 0; i < count; i++)
{
相关文档:
1。首先是基本原理,比如说是life cycle,数据库操作等。
2。实际项目的实践,前一阶段的工作在这个阶段检验,好像做个网站没有想象的那么简单。
3。研究实际的案例和开源框架,到这里才明白,原来网站这么的做的,好像是没有那么难啊。
简单的写写,记录在实际项目中的感悟。于2010-5-30晚,俱乐部。 ......
1. 打开新的窗口并传送参数:
传送参数:
response.write("<script>window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"’)</script>")
接收参数:
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
2.为按钮添加对话框
Button1 ......
1. 打开新的窗口并传送参数:
传送参数:
response.write("<script>window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"’)</script>")
接收参数:
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
2.为按钮添加对话框
Button1 ......
在asp.net里面,很多时候使用session来保存一些对象,比如说购物车等等,有很多时候,就算你设置了session超时的时间,session还是会无缘无故的丢失,这里有一种比较简单的方法可以设置session丢失的时间。
在web.config里面如下配置
<sessionState
& ......