使用System.Web.Mail名称空间连接需要验证的SMTP服务器
2005-01-05 17:04
1071 查看
只需对增加相应标识即可:
// 使用SmtpMail对象发送邮件MailMessage mailObj = new MailMessage();
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置需要验证
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username); //用户名
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password); //密码
--------------示例函数---------------
public void SendMail (string subject,string txt,string mailserver,string username,string password,string from,string sendto)
{
MailMessage mailObj = new MailMessage();
// 设置邮件的发送及接收地址
mailObj.From = from;
mailObj.To = sendto;
mailObj.Subject = subject;
mailObj.Body = txt;
// html格式的邮件
mailObj.BodyFormat = MailFormat.Html;
// 设置为高级优先权
mailObj.Priority = MailPriority.High;
// 为邮件添加附件
// 使用Attachments集合的Add方法创建mailattachment对象添加一个附件到邮件中
//mailObj.Attachments.Add(new MailAttachment("c://test.doc"));
// 使用SmtpMail对象发送邮件
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置需要验证
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username); //用户名
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password); //密码
SmtpMail.SmtpServer=mailserver;
SmtpMail.Send(mailObj);
}
//调用示例
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
SendMail("意见建议",this.TextBox.Text,"mail.orientalwisdom.com","bx133@orientalwisdom.com","123456","bx133@orientalwisdom.com","bx133@orientalwisdom.com");
this.Response.Write("<script>window.alert('您的意见已经提交,感谢您的宝贵建议');</script> ");
this.Response.Write("<script>window.location='../index.aspx';</script>");
}
catch(System.Exception ee )
{
Session["error"]=ee.Message;
Response.BufferOutput=true;
Response.Redirect("errorpage.aspx");
}
}
// 使用SmtpMail对象发送邮件MailMessage mailObj = new MailMessage();
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置需要验证
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username); //用户名
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password); //密码
--------------示例函数---------------
public void SendMail (string subject,string txt,string mailserver,string username,string password,string from,string sendto)
{
MailMessage mailObj = new MailMessage();
// 设置邮件的发送及接收地址
mailObj.From = from;
mailObj.To = sendto;
mailObj.Subject = subject;
mailObj.Body = txt;
// html格式的邮件
mailObj.BodyFormat = MailFormat.Html;
// 设置为高级优先权
mailObj.Priority = MailPriority.High;
// 为邮件添加附件
// 使用Attachments集合的Add方法创建mailattachment对象添加一个附件到邮件中
//mailObj.Attachments.Add(new MailAttachment("c://test.doc"));
// 使用SmtpMail对象发送邮件
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置需要验证
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username); //用户名
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password); //密码
SmtpMail.SmtpServer=mailserver;
SmtpMail.Send(mailObj);
}
//调用示例
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
SendMail("意见建议",this.TextBox.Text,"mail.orientalwisdom.com","bx133@orientalwisdom.com","123456","bx133@orientalwisdom.com","bx133@orientalwisdom.com");
this.Response.Write("<script>window.alert('您的意见已经提交,感谢您的宝贵建议');</script> ");
this.Response.Write("<script>window.location='../index.aspx';</script>");
}
catch(System.Exception ee )
{
Session["error"]=ee.Message;
Response.BufferOutput=true;
Response.Redirect("errorpage.aspx");
}
}
相关文章推荐
- 让微软企业库中的Email Trace Listener使用需要身份验证的SMTP服务器
- 使用system.web.mail.SMTPmail发送邮件,处理smtp验证问题
- 使用需要验证用户的smtp服务器发送邮件
- 163邮箱发送邮件碰到:System.Net.Mail.SmtpException: 不允许使用邮箱名称。 服务器响应为:authentication is required
- .NET 1.1 下不使用 System.Web.Mail.SmtpMail 发送邮件的其它选择
- HttpWebResponse 远程服务器返回错误: (407) 需要代理身份验证。
- Cordova使用SystemWebView加载服务器网址
- 微软BI 之SSIS 系列 - 使用 Script Task 访问非 Windows 验证下的 SMTP 服务器发送邮件
- 使用System.Web.Mail通过需验证的邮件服务器发送邮件
- .net 1.1 下不使用 system.web.mail.smtpmail 发送邮件的其它选择_asp.net技巧
- System.Web.HttpException (0x80004005): 验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保 <machineKey> 配置指定了相同的 validationKey 和验证算法。不能在群集中使用 AutoGenerate。
- 转载:在64位的环境中使用VS建立Web项目进行Oracle连接需要注意WebDev是32位的
- 在IIS中使用Windows域服务器域摘要式身份验证对Web应用程序进行访问控
- 使用System.Web.Mail通过需验证的邮件服务器发送邮件
- 使用System.Web.Mail通过需验证的邮件服务器发送邮件
- 在64位的环境中使用VS建立Web项目进行Oracle连接需要注意WebDev是32位的
- 用Socket发送电子邮件(利用需要验证的SMTP服务器)
- 用Socket发送电子邮件(利用需要验证的SMTP服务器)
- 在IIS中使用Windows域服务器域摘要式身份验证对Web应用程序进行访问