Open Closed

No email sent to email, no error notification, what is missing ? #210


User avatar
0
arifharsono created
  • ABP Framework version: v2.8.0
  • UI type: Angular
  • Tiered (MVC) or Identity Server Seperated (Angular): yes
  • Exception message and stack trace: No Exception, just not working
  • Steps to reproduce the issue:

Related with this documentation : https://docs.abp.io/en/abp/latest/Settings

Problem : No email sent to email recipient, no error notification, what is missing ?

  • Email setting on myApp.Application project:
using Volo.Abp.Emailing;
using Volo.Abp.Settings;
public class AppEmailSettingProvider : SettingDefinitionProvider
    {
        // https://www.emailarchitect.net/easendmail/kb/csharp.aspx?cat=4#send-email-using-office-365
        public override void Define(ISettingDefinitionContext context)
        {
            var Host = context.GetOrNull(EmailSettingNames.Smtp.Host);
            if (Host != null)
            {
                Host.DefaultValue = "smtp.office365.com";
            }

            var Port = context.GetOrNull(EmailSettingNames.Smtp.Port);
            if (Port != null)
            {
                Port.DefaultValue = "587";
            }

            var UserName = context.GetOrNull(EmailSettingNames.Smtp.UserName);
            if (UserName != null)
            {
                UserName.DefaultValue = "noreply@domain.com";
            }

            var Password = context.GetOrNull(EmailSettingNames.Smtp.Password);
            if (Password != null)
            {
                Password.DefaultValue = "password";
            }

            //var Domain = context.GetOrNull(EmailSettingNames.Smtp.Domain);
            //if (Domain != null)
            //{
            //    Domain.DefaultValue = "";
            //}

            var EnableSsl = context.GetOrNull(EmailSettingNames.Smtp.EnableSsl);
            if (EnableSsl != null)
            {
                EnableSsl.DefaultValue = "true";
            }

            var UseDefaultCredentials = context.GetOrNull(EmailSettingNames.Smtp.UseDefaultCredentials);
            if (UseDefaultCredentials != null)
            {
                UseDefaultCredentials.DefaultValue = "false";
            }

            var DefaultFromAddress = context.GetOrNull(EmailSettingNames.DefaultFromAddress);
            if (DefaultFromAddress != null)
            {
                DefaultFromAddress.DefaultValue = "noreply@domain.com";
            }

            var DefaultFromDisplayName = context.GetOrNull(EmailSettingNames.DefaultFromDisplayName);
            if (DefaultFromDisplayName != null)
            {
                DefaultFromDisplayName.DefaultValue = "my Application";
            }
        }
    }
    
    
    * **Application Service :**
    
    using Volo.Abp.Emailing;
    public class MyAppService : ApplicationService, IMyAppService
    {       
        private readonly IEmailSender _emailSender;

        public MyAppService(
            IEmailSender emailSender)
        {
            _emailSender = emailSender;
        }
        
    await _emailSender.SendAsync(
                to: "myclient@domain.com", 
                subject: "Notification emai;", 
                body: $"{employee.Employee.FullName} just request leave approval"
            );

7 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Please provide your logs file

  • User Avatar
    0
    alper created
    Support Team Director

    in debug mode ABP doesn't send email, check your logs to see the email body.

  • User Avatar
    0
    arifharsono created

    ** Build Release > Deploy to Production > Administration Audit Logs :**

    System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength) at System.Convert.FromBase64String(String s) at Volo.Abp.Security.Encryption.StringEncryptionService.Decrypt(String cipherText, String passPhrase, Byte[] salt) at Volo.Abp.Settings.SettingEncryptionService.Decrypt(SettingDefinition settingDefinition, String encryptedValue) at Volo.Abp.Settings.SettingProvider.GetOrNullAsync(String name) at Volo.Abp.Emailing.EmailSenderConfiguration.GetNotEmptySettingValueAsync(String name) at Volo.Abp.Emailing.Smtp.SmtpEmailSender.BuildClientAsync() at Volo.Abp.Emailing.Smtp.SmtpEmailSender.SendEmailAsync(MailMessage mail) at Volo.Abp.Emailing.EmailSenderBase.SendAsync(MailMessage mail, Boolean normalize) at Volo.Abp.Emailing.EmailSenderBase.SendAsync(String to, String subject, String body, Boolean isBodyHtml)

  • User Avatar
    0
    arifharsono created

    in debug mode ABP doesn't send email, check your logs to see the email body.

    Is it possible to check in debug mode ?

  • User Avatar
    0
    alper created
    Support Team Director

    hi the log says your settings for the email is invalid. The password field for the email account is encrypted in AbpSettings table or in the appsettings.json with the name Abp.Mailing.Smtp.Password

    Also in debug mode the implementation of IEmailSender is being replaced by NullEmailSender which doesn't send email, only logs it.

    You can encrypt your password with the IStringEncryptionService

  • User Avatar
    0
    arifharsono created

    Solved, thanks @alper

  • User Avatar
    0
    alexander.nikonov created

    Hi, I am using MailKit + hashed password text and still have the following error:

    using the following setup:

    public class CentralToolsSettingDefinitionProvider : SettingDefinitionProvider
    {
        public override void Define(ISettingDefinitionContext context)
        {
            //Define your own settings here. Example:
            //context.Add(new SettingDefinition(CentralToolsSettings.MySetting1));
    
            context.Add(
                new SettingDefinition("Smtp.Host"),
                new SettingDefinition("Smtp.Port"),
                new SettingDefinition("Smtp.UserName"),
                new SettingDefinition("Smtp.Password", isEncrypted: true),
                new SettingDefinition("Smtp.EnableSsl"),
                new SettingDefinition("Smtp.Domain")
            );
        }
    }
    

    appsettings.json below:

    UPDATE: gave up and just used a plain password storage. I dunno, why Decrypt method does not work...

Made with ❤️ on ABP v9.1.0-preview. Updated on December 26, 2024, 06:07