通过C#发送电子邮件帮助解决错误 [英] Help to solve error with Send Email Message from C#

查看:86
本文介绍了通过C#发送电子邮件帮助解决错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,





我在c#中有以下代码:



Dear Friends,


I have the follow code in c#:

.....
smtpServer="smpt.gmail.com";
#endregion
message.From        = from; // text in from--> 'leochat777@gmail.com'
message.To      = to;   // text in to--> 'leocomp7@yahoo.com'
message.Cc          = cc;
message.Subject     = subject;
message.Priority    = MailPriority.High;
message.Body        = BodyEmail( mensaje, nombreCliente );
message.BodyFormat  = MailFormat.Html;
SmtpMail.SmtpServer = smtpServer;     // text in smtpServer--->'smtp.gmail.com'
try
{
  SmtpMail.Send(message);
  retorna = true;
}
catch(Exception er)
{
  throw new Exception ("Existe un error con el servidor de correo, no pudo enviar el email : "+er.Message,er.InnerException);
}





然后发生错误并说我:



'无法访问'CDO.Message'对象'



并且在捕获内部。



请给我成功发送Messague的解决方案



提前付款

Leonardo Ayala R.



Then ocurr an error and said me:

'cant access to 'CDO.Message' object'

And inside the catch.

Please give me the solution for send the messague successfully

Thanks in advance
Leonardo Ayala R.

推荐答案

如果您完全复制了代码,那么:



If you copied your code exactly, this:

smtpServer="smpt.gmail.com";





应该是这样的:





Should really be this:

smtpServer="smtp.gmail.com";





你写的是smpt,应该是sm tp 。我不确定这是否能解决你的错误,但它是其中之一。您还应该将gmail的端口设置为587我相信而不是默认值。



You wrote smpt when it should be smtp. I'm not sure if this will solve your error, but it is one of them. You should also set the port for gmail to 587 I believe instead of the default.


试试这个



try this

System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.Subject = "Subject";
msg.From = new System.Net.Mail.MailAddress("From");
msg.To.Add(new System.Net.Mail.MailAddress("To"));

msg.IsBodyHtml = true;
msg.Body = "Message Body";
System.Net.Mail.SmtpClient smpt = new System.Net.Mail.SmtpClient();
smpt.Host = "smtp.gmail.com";
smpt.Port = "Port no.(Integer value)";
smpt.EnableSsl = true;
smpt.Credentials = new System.Net.NetworkCredential("(From)User Id", "Password");
smpt.Send(msg);
retVal = true;


这篇关于通过C#发送电子邮件帮助解决错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆