使用System.Web.Mail 发邮件出错!

mythutest 2006-12-18 10:19:52
MailMessage message1 = new MailMessage();
message1.BodyFormat = MailFormat.Html;
message1.Priority = MailPriority.High;
message1.Subject = "Test";
message1.From = "test@163.com";
message1.To = "test1@163.com";
message1.Body = "welcome";
message1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
message1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","test");
message1.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendpassword","test");
SmtpMail.SmtpServer = "smtp.163.com";
SmtpMail.Send(message1);


错误提示:

邮件无法发送到 SMTP 服务器。传输错误代码为 0x80040217。服务器响应为 not available
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: 邮件无法发送到 SMTP 服务器。传输错误代码为 0x80040217。服务器响应为 not available

Source Error:


Line 59: message1.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendpassword","666666");
Line 60: SmtpMail.SmtpServer = "smtp.163.com";
Line 61: SmtpMail.Send(message1);
Line 62: }
Line 63: }
...全文
126 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
cansum396 2006-12-18
  • 打赏
  • 举报
回复
public void SendMail (mailobject mail)
{

MailMessage mailObj = new MailMessage();
// 设置email的'from'和'to'的地址
mailObj.From =mail.MailFrom;
mailObj.To =mail.MailTo;
mailObj.Subject =mail.MailSubject;
mailObj.Body =mail.MailBody;
System.Web.Mail.MailEncoding enc=new MailEncoding();
enc=MailEncoding.Base64;
MailAttachment att=new MailAttachment(mail.Attachments,enc);
mailObj.Attachments.Add(att) ;
// 使用SmtpMail对象来发送邮件。
SmtpMail.SmtpServer=mail.stmpserver;
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",mail.login);
//密码
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",mail.pwd);
SmtpMail.Send(mailObj);
}




public class mailobject
{
public string MailFrom;
public string MailTo;
public string MailSubject;
public string MailBody;
public string MailFormat;
public string mformat;//对邮件进行加密
public string Attachments;//附件
public string stmpserver;
public string login;
public string pwd;
public string email_to;

}

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧