elmah-无法通过电子邮件发送例外 [英] elmah - cannot email exceptions

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

问题描述

对我来说,设置elmah相对比较轻松。直到我尝试使用电子邮件功能。我已经阅读了之前有关该主题的所有问题,但无法解决。这是我的web.config文件中的相关条目。这只是我尝试过的许多尝试之一,这是使用gmail和的尝试。我在做什么错了?

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>

编辑
只是为了证明设置,我已经成功地发送了一封电子邮件使用gmail的应用程序。所使用的设置是等效的,但我仍然无法得到elmah发送电子邮件。

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.

推荐答案

您是否认为GMail的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.

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

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