elmah - cannot email exceptions

牧云@^-^@ 提交于 2019-12-11 10:25:22

问题


Setting up elmah has been relatively painless for me. Until I tried to use the email facility. I have read through all the previous questions on the subject but just can't get it going. Here are the relevant entries in my web.config file . This just represents one of the many attempts that I have made, this one using gmail and . What am I doing wrong?

<elmah>
  <errorMail 
    from="myusername@gmail.com" 
    to="me@myemail.com" 
    subject="elmah exception" 
    async="true" 
    smtpPort="0" 
    useSsl="true" />
</elmah>
<system.net> 
  <mailSettings> 
    <smtp deliveryMethod ="Network"> 
      <network 
        host="smtp.gmail.com" 
        port="587" 
        userName="myusername@gmail.com"   
        password="..." /> 
    </smtp> 
  </mailSettings> 
</system.net>
<httpModules>
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
</httpModules>

EDIT Just to prove the settings, I have managed to successfully send an email from my app using gmail. The settings used were equivalent and yet I still cannot get elmah to send an email. Hers is the code snippet.

  MailMessage mailObj = new MailMessage();
  mailObj.Subject = "gmail test";
  mailObj.From = new System.Net.Mail.MailAddress("myusername@gmail.com");
  mailObj.To.Add("test@myemail.com.au");
  mailObj.Body = "Test Email";

  SmtpClient smtpClient = new SmtpClient("smtp.gmail.com");
  NetworkCredential basicCredential = new NetworkCredential("myusername@gmail.com", "mypassword");
  smtpClient.UseDefaultCredentials = false;
  smtpClient.Credentials = basicCredential;
  smtpClient.Port = 587;
  smtpClient.EnableSsl = true;
  smtpClient.Send(mailObj);

Even some confirmation that it all appears correct would be useful.


回答1:


the port is 465 and the protocol is SSL.




回答2:


Did you consider any ill effects from GMail's 2-factor authentication? I was just having this problem and created an application-specific password for my development work.



来源:https://stackoverflow.com/questions/9694873/elmah-cannot-email-exceptions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!