邮件发送问题 [英] Problem with mail sending

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

问题描述

大家好!

我正尝试从我的网站发送错误日志电子邮件,但每次都会弹出以下错误..

Hi all!!

i am trying to send error log email from my site but the following error pops up everytime..

Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 74.125.236.86 (74.125.236.86:587), connect error 10060





MailClient.Credentials = new NetworkCredential(MonalConfiguration.MailUsername, MonalConfiguration.MailPassword);

MailMessage mailmessage = new MailMessage(from, to, subject, body);

MailClient.Send(mailmessage);





这是我的web.cofig中的设置





Here are the settings in my web.cofig

<appSettings>
    <add key="MailServer" value="mail.google.com"/>
    <add key="MailUsername" value="UserName@gmail.com"/>
    <add key="MailPassword" value="Password"/>
    <add key="MailFrom" value="UserName@gmail.com"/>
    <add key="EnableErrorLogEmail" value="true"/>
    <add key="ErrorLogEmail" value="ujjwal.uniyal111@gmail.com"/>
  </appSettings>





这是我的配置文件





this is my configuration file

public static  class MonalConfiguration
{
    private static string dbConnectionString;
    private static string dbProviderName;

    static  MonalConfiguration()
    {
        dbConnectionString = ConfigurationManager.ConnectionStrings["Constr"].ConnectionString;
        dbProviderName = ConfigurationManager.ConnectionStrings["Constr"].ProviderName;
    }

    public static string DbConnectionString
    {
        get { return dbConnectionString; }

    }
    public static string DbProviderName
    {
        get { return dbProviderName; }
    }

    public static string MailServer
    {
        get {  return ConfigurationManager.AppSettings["MailServer"];}
    }

    public static string MailUsername
    {
        get { return ConfigurationManager.AppSettings["MailUsername"] ;}
    }

    public static string MailFrom
    {
        get { return ConfigurationManager.AppSettings["MailFrom"] ;}
    }

    public static string MailPassword
    {
        get { return ConfigurationManager.AppSettings["MailPassword"];}
    }

    public static bool EnableErrorLogEmail
    {
        get { return bool.Parse (ConfigurationManager.AppSettings["EnableErrorLogEmail"]); }
    }
    public static string ErrorLogEmail
    {
        get { return ConfigurationManager.AppSettings["ErrorLogEmail"]; }
    }
}

推荐答案

您错过了stmp端口号,应该启用sl.在此处阅读 [
you miss the stmp port number and you should enablessl. Read it here[^]


我更改了密钥=" MailServer"从value ="mail.google.com"发送到

值="smtp.gmail.com"

效果很好...
I changed the value of key ="MailServer" from value="mail.google.com" to

value ="smtp.gmail.com"

and it worked fine...


尝试这个

try this

MailAddress mailfrom = new MailAddress ( "frommail@gmail.com" );
MailAddress mailto = new MailAddress ( "tomail@gmail.com" );
MailMessage newmsg = new MailMessage ( mailfrom, mailto );
newmsg.Subject = "Subject of Email";
newmsg.Body = "Body(message) of email";
////For File Attachment, more file can also be attached
Attachment att = new Attachment ( "G:\\code.txt" );
newmsg.Attachments.Add ( att );
SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 );
smtps.UseDefaultCredentials = false;
smtps.Credentials = new NetworkCredential ( "urmail@gmail.com", "urpwd" );
smtps.EnableSsl = true;
smtps.Send ( newmsg );



System.Net.Mail命名空间 [



System.Net.Mail Namespace[^]


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

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