使用 SmtpEmailSender 在 abp io 中发送电子邮件 throwing The input is not a valid Base-64 string

Sending Email in abp io with SmtpEmailSender throwing The input is not a valid Base-64 string

我已经尝试了一个星期来发送电子邮件,但没有成功。 我的测试是发送电子邮件以重置密码

appsettings.json

我的应用程序的设置提供商

和我的应用程序的 DomainModule

我一直在查看官方文档,但不幸的是,它含糊不清且不详细。

点击忘记密码后,输入邮箱,点击发送弹出这个错误

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.
System.Convert.FromBase64CharPtr(Char* inputPtr, int inputLength)
System.Convert.FromBase64String(string s)
Volo.Abp.Security.Encryption.StringEncryptionService.Decrypt(string cipherText, string passPhrase, byte[] salt)
Volo.Abp.Settings.SettingEncryptionService.Decrypt(SettingDefinition settingDefinition, string encryptedValue)
Volo.Abp.Settings.SettingProvider.GetOrNullAsync(string name)
Volo.Abp.Emailing.EmailSenderConfiguration.GetNotEmptySettingValueAsync(string name)
Volo.Abp.Emailing.Smtp.SmtpEmailSender.BuildClientAsync()
Volo.Abp.Emailing.Smtp.SmtpEmailSender.SendEmailAsync(MailMessage mail)
Volo.Abp.Emailing.EmailSenderBase.SendAsync(MailMessage mail, bool normalize)
Volo.Abp.Emailing.EmailSenderBase.SendAsync(string to, string subject, string body, bool isBodyHtml)
Volo.Abp.Account.Emailing.AccountEmailer.SendPasswordResetLinkAsync(IdentityUser user, string resetToken, string appName, string returnUrl, string returnUrlHash)
Volo.Abp.Account.AccountAppService.SendPasswordResetCodeAsync(SendPasswordResetCodeDto input)

您必须将密码的加密版本存储在 appsettings.json

只需在您应用的某处使用此代码段

public class EmailSettingProvider : SettingDefinitionProvider
{
    private readonly ISettingEncryptionService encryptionService;

    public EmailSettingProvider(ISettingEncryptionService encryptionService)
    {
        this.encryptionService = encryptionService;
    }

    public override void Define(ISettingDefinitionContext context)
    {
        var passSetting = context.GetOrNull("Abp.Mailing.Smtp.Password");
        if(passSetting!=null)
        {
            string debug = encryptionService.Encrypt(passSetting,"1q2w3e$R");
        }
    }
}  

设置一个断点并将debug变量中的值复制到appsettings.json文件中,这就是您需要的所有配置。