1

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.

crackles
  • 181
  • 1
  • 10
  • You've misspelled 'smtpPort' in your /elmah/errorMail element - and port 0 probably isn't correct there. –  Mar 14 '12 at 03:49
  • Thank you for pointing out my dyslexia, I will edit the original. Unfortunately, even with it spelled correctly it still doesn't work. By setting smtpPort="0" it apparently uses the port specified in the section. I have tried the option of explicitly setting the port to 587 but it still doesn't work. – crackles Mar 14 '12 at 05:00

2 Answers2

0

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.

beaudetious
  • 2,354
  • 3
  • 36
  • 60
0

the port is 465 and the protocol is SSL.

icomrade
  • 1,053
  • 1
  • 9
  • 11
  • Thanks for your suggestion but 465 does not work either for me. I had already set SSL with useSsl="true" – crackles Mar 15 '12 at 03:37
  • You can try following this guide, I'm not familiar with elmah so i'm not sure if this will work for you. good luck http://scottonwriting.net/sowblog/archive/2009/05/21/163350.aspx Also, if you are using a google apps domain you have to set it to allow external smtp relaying in the admin cp. – icomrade Mar 19 '12 at 04:13