https://docs.abp.io/en/abp/latest/Emailing
Encrypt the SMTP Password
Abp.Mailing.Smtp.Password must be an encrypted value. If you use the ISettingManager to set the password, you don't have to worry. It internally encrypts the values on set and decrypts on get.
If you use the appsettings.json to store the password, you should manually inject the ISettingEncryptionService and use its Encrypt method to obtain an encrypted value. This can be done by creating a simple code in your application. Then you can delete the code. As better, you can create a UI in your application to configure the email settings. In this case, you can directly use the ISettingManager without worrying the encryption.
using Volo.Abp.Emailing;
using Volo.Abp.Settings;
namespace AbpManaul.Application.Settings;
public class SettingService
{
private readonly ISettingEncryptionService _settingEncryptionService;
private readonly ISettingDefinitionManager _settingDefinitionManager;
public SettingService(
ISettingEncryptionService settingEncryptionService,
ISettingDefinitionManager settingDefinitionManager)
{
_settingEncryptionService = settingEncryptionService;
_settingDefinitionManager = settingDefinitionManager;
}
public string EncryptMailingSmtpPassword(string passsword)
{
var setting = _settingDefinitionManager.Get(EmailSettingNames.Smtp.Password);
var encryptPassword = _settingEncryptionService.Encrypt(setting, passsword);
return encryptPassword;
}
}
for example:
call EncryptMailingSmtpPassword(123)
return "3zil2vJ325s+uboMEiKCDA=="
then set Abp.Mailing.Smtp.Password
in the appsettings.json
as following:
"Settings": {
...
"Abp.Mailing.Smtp.Password": "3zil2vJ325s+uboMEiKCDA==",
...
},
标签:vNext,use,Smtp,settingDefinitionManager,Abp,Password,settingEncryptionService,邮件
From: https://www.cnblogs.com/easy5weikai/p/16885836.html