Open Closed

Email not sending despite testing SMTP info and applying recommended fixes on forum .. #6095


0
jchester26 created

Hi,

Emails are not sending and I would like some help trying to reolve as I am spending a lot of time with no success. I have reviewed the support forum and tried several fixes but still no success.

  • I have tested all of my SMTP settings sing SMTPProbe and that succesfully sends emails from the same machine (host, port, user, password, authentication)
  • I have commented out '//Configuration.ReplaceService<IEmailSender, NullEmailSender>(DependencyLifeStyle.Transient);' in Module Preinitialization so that emails are sent in debug mode
  • I have added 'Configuration.Modules.AbpMailKit().SecureSocketOption = SecureSocketOptions.Auto;' line to Preinitiialization in XYZCoreModule.cs
  • I have not added any code to XYZSmtpEmailSenderConfiguration class in XYZSmtpEmailSenderConfiguration.cs

The log file records the following;

`ERROR 2018-12-05 09:39:43,418 [56   ] Mvc.ExceptionHandling.AbpExceptionFilter - An error occurred while attempting to establish an SSL or TLS connection.

The SSL certificate presented by the server is not trusted by the system for one or more of the following reasons:
1. The server is using a self-signed certificate which cannot be verified.
2. The local system is missing a Root or Intermediate certificate needed to verify the server's certificate.
3. The certificate presented by the server is expired or invalid.

See https://github.com/jstedfast/MailKit/blob/master/FAQ.md#InvalidSslCertificate for possible solutions.
MailKit.Security.SslHandshakeException: An error occurred while attempting to establish an SSL or TLS connection.

The SSL certificate presented by the server is not trusted by the system for one or more of the following reasons:
1. The server is using a self-signed certificate which cannot be verified.
2. The local system is missing a Root or Intermediate certificate needed to verify the server's certificate.
3. The certificate presented by the server is expired or invalid.

See https://github.com/jstedfast/MailKit/blob/master/FAQ.md#InvalidSslCertificate for possible solutions. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.`

When I investigated that problem, the recommendation was to add the Configuration.Modules.AbpMailKit().SecureSocketOption = SecureSocketOptions.Auto; setting in the module preinitialisation, which I have done.

I am using SendGrid SMTP server, but I am not sure that is the issue as I can succesfully send an Email using STMPProbe app from the same machine. the STMP setting for that are smtp.sendgrid.net, port 587, username apikey and pwd [not included here]

Can anyone offer any more advice?

Thanks!


11 Answer(s)
  • 0
    jchester26 created

    Hi,

    Update. I have tried using Gmail SMTP as suggested in thos post by @ismcagdas https://support.aspnetzero.com/QA/Questions/4360

    The exact same error occurs and the exact same log file entries.

    Any help from support?

    Thanks

    J

  • 0
    ismcagdas created
    Support Team

    Hi @jchester26

    This problem should be fixed via https://github.com/aspnetzero/aspnet-zero-core/commit/a42ec83d307c35cc5e3b68c51678acc647e75b5b.

    Could you try that in your solution as well ?

  • 0
    jchester26 created

    Hi @ismcagdas

    I get a pgae not found when going to the link you posted.

  • 0
    jchester26 created

    Hi @ismcagdas. OK got the page now.

    I have made the changes to module preinitialisation. However the file AbpZeroTemplateMailKitSmtpBuilder.cs does not exist at this path, I have

    src/XYZ.Core/Emailing/XYZSmtpEmailSenderConfiguration.cs

    Shall I make the changes in that file or create a new XYZMailKitSmtpBuilder.cs file?

  • 0
    jchester26 created

    Hi @ismcagdas

    Yes! That worked thank you. I added the new code as an additonal public class in my existing file.

    Just one final question. When I first changed it I was using the wrong port number and an exception was thrown in the IDE and I had to continue. Is that becuase I am in debug mode? I would not want the system to stop if an exception was thown in production for a timeout if the SMTP server was unavailable.

  • 0
    ismcagdas created
    Support Team

    When I first changed it I was using the wrong port number and an exception was thrown in the IDE and I had to continue

    Yes, if you were debugging the source code, this is the expected behaviour. If you run the project using CTRL + F5 or if your project is running in the production, you will not see such a heavior.

  • 0
    jaycee26 created

    Thank you for your help.

  • 0
    johntui created

    Hi, I know this is an old thread but I'm having this exact same problem. @ismcagdas - the link you posted returns a page not found. @jaycee26 Could you share what was the solution please?

  • 0
    jaycee26 created

    @johntui you need to be signed in to GitHub in order to see the page, otherwise you get 404 Page Not Found. You also need access to the AspNetZero repository on Github.

    But the following was what that commit is, and what I did to get it working;

    In aspnet-core/src/MyCompanyName.AbpZeroTemplate.Core/AbpZeroTemplateCoreModule.cs

    Add ` using MailKit.Net.Smtp; using MailKit.Security;``

    And then in the PreIntitialize() Method:

             // MailKit configuration
             Configuration.Modules.AbpMailKit().SecureSocketOption = SecureSocketOptions.Auto;
             Configuration.ReplaceService<IMailKitSmtpBuilder, AbpZeroTemplateMailKitSmtpBuilder>(DependencyLifeStyle.Transient);
    

    `

    Then in aspnet-core/src/MyCompanyName.AbpZeroTemplate.Core/Net/Emailing/AbpZeroTemplateMailKitSmtpBuilder.cs

    `using Abp.MailKit; using Abp.Net.Mail.Smtp; using MailKit.Net.Smtp;

    namespace MyCompanyName.AbpZeroTemplate.Net.Emailing { public class AbpZeroTemplateMailKitSmtpBuilder : DefaultMailKitSmtpBuilder { public AbpZeroTemplateMailKitSmtpBuilder( ISmtpEmailSenderConfiguration smtpEmailSenderConfiguration, IAbpMailKitConfiguration abpMailKitConfiguration) : base(smtpEmailSenderConfiguration, abpMailKitConfiguration) {

         }
    
         protected override void ConfigureClient(SmtpClient client)
         {
             client.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
             base.ConfigureClient(client);
         }
     }
    

    }``

  • 0
    johntui created

    Looks like I've got all those in place already and am still getting the error. Will keep looking for solution.

    Thanks for you help @Jaycee26.

  • 0
    jaycee26 created

    @johntui - OK, sorry it does not work. My solution works with the template 9.3 version using sendgrid.
    The only change I made was to enable email sending in debug mode for testing. Other than that, in case it helps here are the SMTP settings I am using;

    SMTP host = smtp.sendgrid.net SMTP port = 465 Use SSL = ticked Domain name = sendgrid.net user name = apikey password = my api token from sendgrid account