abp icon indicating copy to clipboard operation
abp copied to clipboard

Sending email as Tenant produces error "Padding is invalid and cannot be removed."

Open GeertVeenstra opened this issue 4 years ago • 5 comments

  • ABP Framework version : 5.0.0

  • User Interface: MVC

  • Database provider: EF Core

  • Exception message: [ERR] Padding is invalid and cannot be removed.

  • Steps to reproduce:

  1. Create Global email settings
  2. Override Abp.Mailing.DefaultFromDisplayName from Tenant
  3. Send email from Tenant await _emailSender.SendAsync(emailAddress, subject, body);

Sending emails from Host is working correctly.

Also noticed that when you enter the email settings from the Tenant (the exact same settings as entered on host level), then the password setting is Abp.Mailing.Smtp.Password is in the Settings table for both Host as well as Tenant (even though the encrypted string is the same).

Geert Veenstra

GeertVeenstra avatar Dec 16 '21 07:12 GeertVeenstra

What's the full error stack?

maliming avatar Dec 16 '21 07:12 maliming

   at Internal.Cryptography.UniversalCryptoDecryptor.GetPaddingLength(ReadOnlySpan`1 block)
   at Internal.Cryptography.UniversalCryptoDecryptor.UncheckedTransformFinalBlock(ReadOnlySpan`1 inputBuffer, Span`1 outputBuffer)
   at Internal.Cryptography.UniversalCryptoDecryptor.UncheckedTransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
   at Internal.Cryptography.UniversalCryptoTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
   at System.Security.Cryptography.CryptoStream.<ReadAsyncCore>d__44.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   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>d__10.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Volo.Abp.Emailing.EmailSenderConfiguration.<GetNotEmptySettingValueAsync>d__6.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Volo.Abp.Emailing.Smtp.SmtpEmailSender.<BuildClientAsync>d__4.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Volo.Abp.Emailing.Smtp.SmtpEmailSender.<SendEmailAsync>d__5.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Volo.Abp.Emailing.EmailSenderBase.<SendAsync>d__9.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Volo.Abp.Emailing.EmailSenderBase.<SendAsync>d__7.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at SuB.WebPay.Web.Public.Pages.Receipts.ReceiptEmailModalModel.<OnPostAsync>d__12.MoveNext() in C:\OneDrive - sbps\Development\Repos\Websites\SuB.WebPay\src\SuB.WebPay.Web.Public\Pages\Receipts\ReceiptEmailModal.cshtml.cs:line 57

GeertVeenstra avatar Dec 16 '21 08:12 GeertVeenstra

Also happens when I do not make any Tenant specific email settings (just using host settings).

GeertVeenstra avatar Dec 16 '21 08:12 GeertVeenstra

Can you share the detailed steps to reproduce from a template project?

maliming avatar Dec 16 '21 08:12 maliming

Hi,

Sorry, my bad. I could not reproduce it in a template project and compared it with my own code.

I was sending the emails from the public website project and the StringEncryption setting was missing in the appsettings.json for that project. It is working now.

Geert Veenstra

GeertVeenstra avatar Dec 16 '21 08:12 GeertVeenstra