I am using aspNetBoilerplate to send an email (or attempt to send an email)
I have added the settings to the database using the Default Settings Creator in the seed data like so
namespace ESMPortal.EntityFrameworkCore.Seed.Host
{
public class DefaultSettingsCreator
{
private readonly ESMPortalDbContext _context;
public DefaultSettingsCreator(ESMPortalDbContext context)
{
_context = context;
}
public void Create()
{
// Emailing
AddSettingIfNotExists(EmailSettingNames.DefaultFromAddress, "system@elite-sports-management.co.uk");
AddSettingIfNotExists(EmailSettingNames.DefaultFromDisplayName, "Elite Sports Management");
AddSettingIfNotExists(EmailSettingNames.Smtp.Host, "mail.x.co.uk");
AddSettingIfNotExists(EmailSettingNames.Smtp.Password, "xxx");
AddSettingIfNotExists(EmailSettingNames.Smtp.UserName, "system@x.co.uk");
AddSettingIfNotExists(EmailSettingNames.Smtp.EnableSsl, "true");
// Languages
AddSettingIfNotExists(LocalizationSettingNames.DefaultLanguage, "en");
}
private void AddSettingIfNotExists(string name, string value, int? tenantId = null)
{
if (_context.Settings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null))
{
return;
}
_context.Settings.Add(new Setting(tenantId, null, name, value));
_context.SaveChanges();
}
}
}
I have confirmed that these settings are added to the database when the project runs
However when i attempt to send an email i get an error stating that the server at 127.0.0.1:25 did not respond. This obviously means that the settings in the database arn't being used.
This is further confirmed when i dont include a from address when sending an email. I receive an error saying that the DefaultFromAddress is null or empty. This is not the case as i have confirmed it is present in the database settings table.
Here is the code that im using to send the email. All the above errors are generated in the catch section of the try statement
try
{
_emailSender.Send(
to: userId.EmailAddress,
from: "system@x.co.uk",
subject: "New Upload",
body: $"A new upload is assigned to you: <b>{upload.DisplayName}</b>",
isBodyHtml: true
);
}
catch (Exception e)
{
throw;
}