读书人

System.Web.Mail发邮件总出现CDO.MESS

发布时间: 2011-12-27 22:22:55 作者: rapoo

System.Web.Mail发邮件总出现CDO.MESSAGE错误
#region 邮件发送
private void btn_send_Click(object sender, System.EventArgs e)
{
MailMessage c_mail = new MailMessage();

c_mail.To = this.ddl_Receiver.SelectedValue.ToString();

c_mail.From = this.ddl_SendMan.SelectedValue.ToString();

c_mail.Subject = this.txt_Subject.Text.ToString();

c_mail.Body = this.txt_Content.Text.ToString();

c_mail.Priority = MailPriority.Normal;

c_mail.BodyFormat = MailFormat.Text;

if(this.FileUpload.PostedFile.FileName != " ")
{
string filename = FileUpload.PostedFile.FileName;

filename = System.IO.Path.GetFileName(filename);
//filename = filename.Substring(filename.LastIndexOf(@ "\ "));
filename = Server.MapPath(@ ".\temp\ " + filename);
FileUpload.PostedFile.SaveAs(filename);
c_mail.Attachments.Add(new MailAttachment(filename));
}
string str_msg = " ";
try
{
c_mail.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ", "1 ");//设置服务器需要身份验证
c_mail.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername ", "elf_eflboy "); //设置用户名
c_mail.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword ", "8101292 ");//设置密码

SmtpMail.SmtpServer= "smtp.163.com ";//设置邮件服务器地址

//SmtpMail.Send(c_mail);
}


大家忙吧解决下吧.

[解决办法]
是这样的,这个异常到现在还没有人解决


[解决办法]
你检查一下你的用户名跟密码是否正确?确认无误后检查下你的c_mail.From值.这个应该跟你的用户名是一致的..
[解决办法]
#region 邮件发送的类

/// <summary>
/// 邮件发送的类
/// </summary>
public class SystemMail

{

private string _adminEmail;

private string _smtpServer = "localhost ";

private string _password;

private string _userName;

private string _mailFormat;


public SystemMail()

{

}

public string AdminEmail

{

get{return _adminEmail;}

set{_adminEmail = value;}

}

public string SmtpServer

{

get{return _smtpServer;}

set{_smtpServer = value;}

}

public string Password

{

get{return _password;}

set{_password = value;}

}

public string UserName

{

get{return _userName;}

set{_userName = value;}

}

public string EMailFormat

{

get{return _mailFormat;}

set{_mailFormat = value;}

}

public bool Send(string to, string from, string subject, string message)

{

try

{

MailMessage em = new MailMessage();

em.To = to;

em.From = from;

em.Subject = subject;


em.Body = message;

if (this.EMailFormat== "Html ")
{
em.BodyFormat=MailFormat.Html;
}


//Found out how to send authenticated email via System.Web.Mail at http://SystemWebMail.com (fact 3.8)

if(this.UserName != null && this.Password != null)

{

em.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ", "1 "); //basic authentication

em.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername ", this.UserName); //set your username here

em.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword ", this.Password); //set your password here

}

SmtpMail.SmtpServer = this.SmtpServer;

SmtpMail.Send(em);

return true;

}

catch

{
return false;

}
}
}

#endregion
===========================================
Manage.SystemMail SM=new Manage.SystemMail();
SM.AdminEmail= "xxx@163.com ";
SM.UserName= "xxx@163.com ";
SM.Password= "xxx ";
SM.SmtpServer= "smtp.163.com ";
string mailContent= "xxxxxx "
SM.Send(Email.Text.ToString(), "xxx@163.com ", "xxxx ",mailContent);

读书人网 >asp.net

热点推荐