无法发送邮件 [英] Not able to send mails

查看:63
本文介绍了无法发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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("emailid@gmail.com");
                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="emailid@gmail.com" password="pwdxyz"/>
      </smtp>
    </mailSettings>    
  </system.net>

推荐答案

授权。



您几乎肯定需要授权:使用C#发送电子邮件或没有附件:通用例程。 [ ^ ]包含它。


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


这篇关于无法发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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