日期:2014-05-18  浏览次数:20549 次

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;