Open Closed

Send email not working why ? #9347


User avatar
0
devmahmod created

I want to send email in project mvc core multi layer this is my settings in app settings of web application project

{
  "App": {
    "SelfUrl": "https://localhost:44307",
    "DisablePII": false,
    "HealthCheckUrl": "/health-status",
    "BaseUrl": "http://192.168.1.239:8082"
  },
  "Redis": {
    "Configuration": "127.0.0.1"
  },
  "ConnectionStrings": {
    "Default": "Server=.;Database=SCISP;Trusted_Connection=True;TrustServerCertificate=true"
  },
  "AuthServer": {
    "Authority": "https://localhost:44307",
    "RequireHttpsMetadata": true,
    "CertificatePassPhrase": "cc3ed157-60af-42a7-a75c-7e32293e42a2"
  },
  "StringEncryption": {
    "DefaultPassPhrase": "zKWlXT8wjrpLf5P3"
  },
  "OpenIddict": {
    "Encryption": {
      "Certificate": {
        "Path": "openiddict.pfx",
        "Password": "SecurePassword123!"
      }
    }
  },
    "Settings": {
      "Abp.Mailing.DefaultFromAddress": "smtp.gmail.com",
      "Abp.Mailing.DefaultFromDisplayName": "My Application",
      "Abp.Mailing.Smtp.Host": "smtp.gmail.com",
      "Abp.Mailing.Smtp.Port": "587",
      "Abp.Mailing.Smtp.UserName": "devmahmod@gmail.com",
      "Abp.Mailing.Smtp.Password": "fpiocvidrhkwondc",
      "Abp.Mailing.Smtp.EnableSsl": "True"
    }
  }

and i'm use abp code

private readonly IEmailSender _emailSender; and inject in constructor and my code is     try
    {
        await SendEmailToUsersInRoleAsync(
               usersInRole,
               $"New Request: {type} - {requestNumber}",
               $"A new request has been submitted and assigned to you.\nRequest ID: {requestNumber}"
         );
    }
    catch (Exception ex)
    {

        throw;
    } 
     private async Task SendEmailToUsersInRoleAsync(
IList<IdentityUser> users,
string subject,
string body,
bool isBodyHtml = false)
 {
     foreach (var user in users)
     {
         if (!string.IsNullOrWhiteSpace(user.Email))
         {
             await _emailSender.SendAsync(
                 to: user.Email,
                 subject: subject,
                 body: body,
                 isBodyHtml: isBodyHtml
             );
         }
     }
 }

2 Answer(s)
  • User Avatar
    0
    roberto.fiocchi created

    In Debug Mode you generally don't want to send real emails,this is what the abp guide says :) https://abp.io/docs/latest/framework/infrastructure/emailing?#nullemailsender

    Also, the password ("Abp.Mailing.Smtp.Password") must be encrypted https://abp.io/docs/latest/framework/infrastructure/emailing?_redirected=B8ABF606AA1BDF5C629883DF1061649A#encrypt-the-smtp-password

    I hope I was helpful.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can use this sample to test your Abp.Mailing configuration

    1. The Password of Abp.Mailing.Smtp.Password in appsettings.json file needs to encrypt!
    2. Please use the IStringEncryptionService to encrypt the plain text password.
    3. Note that encryption may be affected by the configuration of StringEncryption:DefaultPassPhrase in appsettings.json.

    https://github.com/abpframework/abp-samples/tree/master/EmailSendDemo

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on June 13, 2025, 11:37