ASP.NET通过QQ邮箱发送邮件以及发送附件

 1 protected void Button1_Click(object sender, EventArgs e)
 2         {
 3             SendSMTPEMail("smtp.qq.com", "发件人邮箱@qq.com", "发件人授权码", "收件人@qq.com", "测试邮件", "用asp.net发送邮件,用qq的smtp.qq.com服务器,测试成功");
 4         }
 5         public void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody)
 6         {
 7             System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer);
 8             client.UseDefaultCredentials = false;
 9             client.EnableSsl = true;
10             client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);
11             client.DeliveryMethod = SmtpDeliveryMethod.Network;
12             System.Net.Mail.MailMessage message = new MailMessage(strFrom, strto, strSubject, strBody);
13             message.BodyEncoding = System.Text.Encoding.UTF8;
14             message.IsBodyHtml = true;
15 
16             //使用文件路径发送附件
17             //AlternateView item = new AlternateView(@"D:\\软件\\(软电话)eyebeam1.5.rar", "application/x-rar-compressed");
18             //message.AlternateViews.Add(item);
19             //message.AlternateViews.Dispose();
20 
21             //使用Stream发送附件 
22             //Attachment letter = new Attachment(FileUploadLetter.FileContent, FileUploadLetter.PostedFile.ContentType);
23             //letter.ContentDisposition.Inline = true;
24             //letter.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
25             ////inline.ContentId = "1";
26             //letter.ContentType.MediaType = FileUploadLetter.PostedFile.ContentType;
27             //letter.ContentType.Name = Path.GetFileName(FileUploadLetter.PostedFile.FileName);
28             //letter.Name = Path.GetFileName(FileUploadLetter.PostedFile.FileName);
29             //message.Attachments.Add(letter);
30             //message.Attachments.Dispose();
31            
32             client.Send(message);
33         }

 

posted @ 2016-08-26 17:13  zhang_r  阅读(1391)  评论(0编辑  收藏  举报