本文介绍了无法发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
My code is like this its working fine when i run the solution in local system but am not not able to send mails when i published it to server what might be wrong??
public static bool SendMail(string MailTo, string MailCC, string MailBCC, string MailSubject, string MailBody)
{
bool _Success = false;
try
{
SmtpClient smtp = new SmtpClient();
MailMessage message = new MailMessage();
message.IsBodyHtml = true;
message.From = new MailAddress("[email protected]");
message.To.Add(MailTo);
message.CC.Add(new MailAddress(MailCC));
message.Subject = MailSubject;
message.Body = MailBody;
smtp.EnableSsl = true;
smtp.Send(message);
_Success = true;
}
catch (Exception ex)
{
ExceptionLogging("Common", "Common.SendMail()", ex.ToString());
_Success=false;
}
return _Success;
}
web config file is like this
<system.net>
<mailSettings>
<smtp>
<network host="smtp.gmail.com" port="587" userName="[email protected]" password="pwdxyz"/>
</smtp>
</mailSettings>
</system.net>
推荐答案
i was using smptclient instead of smtpserver final got it with little tweaks.. thanku guys for giving suggestions :)
const string SERVER = "serverHosting name";
System.Web.Mail.MailMessage oMail = new System.Web.Mail.MailMessage();
oMail.From = "emailname@yourdomain";
oMail.To = MailTo;
oMail.Cc = MailCC;
oMail.Subject = MailSubject;
oMail.BodyFormat = MailFormat.Html; // enumeration
oMail.Priority = MailPriority.High; // enumeration
oMail.Body = MailBody;
SmtpMail.SmtpServer = SERVER;
SmtpMail.Send(oMail);
oMail = null; // free up resources
这篇关于无法发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!