欢迎光临

木子屋

标题: C#发送邮件示例

作者: dnawo

日期: 2009-12-18 12:10 AM

分类: Win编程

内容: 复制内容到剪贴板 程序代码//using System.Net;
//using System.Net.Mail;
//using System.Text;
//电子邮件
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("111111@qq.com", "张三");//发件人
mailMessage.To.Add(new MailAddress("222222@qq.com", "李四"));//收件人
mailMessage.To.Add(new MailAddress("333333@qq.com", "王五"));//收件人
mailMessage.CC.Add(new MailAddress("444444@qq.com", "小二"));//抄送人
mailMessage.Priority = MailPriority.Normal;//优先级
mailMessage.SubjectEncoding = Encoding.UTF8;
mailMessage.Subject = "Happy New Year!";//标题
mailMessage.BodyEncoding = Encoding.UTF8;
mailMessage.IsBodyHtml = true;
mailMessage.Body = "<font color=red>Hello,Happy New Year!</font>";//内容
mailMessage.Attachments.Add(new Attachment(@"F:\Me.jpg"));//附件
//邮件服务器
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = "smtp服务器地址";
smtpClient.Credentials = new NetworkCredential("用户名", "用户密码");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Send(mailMessage);
-------------------------------------------------------
问：QQ邮箱发送失败服务器响应Error: need EHLO and AUTH first怎么解决？
答：登录QQ邮箱申请授权码，上边代码做如下修改：
复制内容到剪贴板 程序代码smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential("用户名", "申请的授权码");

+ 查看当前日志评论 (0)

登录

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 2.910 ms

返回

标题: C#发送邮件示例

你没有权限发表评论

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 2.910 ms

返回

暂无评论

返回

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 2.984 ms

返回