Open Closed

SMTP setup #2269


User avatar
0
shobhit created
  • ABP Framework version: v4.2.2
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:NA
  • Steps to reproduce the issue:"NA

I have to configure gmail smtp. It is not working as per my current setup. Please find below the smtp details.

 "Abp.Mailing.Smtp.Host": "smtp.gmail.com",
"Abp.Mailing.Smtp.Port": "587",
"Abp.Mailing.Smtp.UserName": "aztutedev11@gmail.com",
"Abp.Mailing.Smtp.Password": "$^&%^(*&FGJHGKJ", //Hased password
"Abp.Mailing.Smtp.Domain": "",
"Abp.Mailing.Smtp.EnableSsl": "true",
"Abp.Mailing.Smtp.UseDefaultCredentials": "false",
"Abp.Mailing.DefaultFromAddress": "aztutedev11@gmail.com",
"Abp.Mailing.DefaultFromDisplayName": "Aztute Command Center",

25 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You can use this to test the configure of email.

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

  • User Avatar
    0
    shobhit created

    Hello maliming, Thanks for help. current solution is working fine but our app is not sending the confirmation email while creating new user. Consider following steps:

    1-	Email confirmation enabled
    

    2- SMTP configured in Host Json 3- NOTE: We have overridden the User creation App service like below sample

    public class MyIdentityUserAppService : IdentityUserAppService
    {
        public override async Task<IdentityUserDto> CreateAsync(IdentityUserCreateDto input)
        {
            IdentityUserDto identityUserDto = await base.CreateAsync(input);
    
           
            return identityUserDto;
        }
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Can you try to remove this?

    #if DEBUG
                context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>());
    #endif
    
  • User Avatar
    0
    shobhit created

    Where exactly i have to replace

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You just need to remove the NullEmailSender. Global search NullEmailSender in your solution.

  • User Avatar
    0
    shobhit created

    still not working i.e. not receiving email.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Check your app logs.

  • User Avatar
    0
    shobhit created

    Host Logs have no Error [ERR] record

  • User Avatar
    0
    shobhit created

    During debug got following error message: {"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."}

  • User Avatar
    0
    shobhit created

    Getting above error from:

    await EmailSender.SendAsync( user.Email, "EmailConfirmation", emailContent,true );

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

  • User Avatar
    0
    shobhit created

    hi Maliming, Thanks for help. Now i am receiving email but i have to do few more changes in my CreateUser Method:

    public override async Task<IdentityUserDto> CreateAsync(IdentityUserCreateDto input) { IdentityUserDto identityUserDto = await base.CreateAsync(input);

            var user = await _identityUserRepository.FindByNormalizedEmailAsync(input.Email.ToUpperInvariant());
    
            var confirmationToken = await UserManager.GenerateEmailConfirmationTokenAsync(user);
    
            await _AccountEmailer.SendEmailConfirmationLinkAsync(user, confirmationToken, "MVC", "https://localhost:4200");
           
            return identityUserDto;
        }
        
    

    Now i have 2 challenges:

    1- i am not getting full url but getting like this which is missing the domain: /Account/EmailConfirmation?userId=e3eecf67-85fc-59eb-face-3a00cf032a62&tenantId=&confirmationToken=CfDJ8M3speqUcVZAto9TzzaT5%2BngwUFUIw%2Fta3OQuB7gt8dBiWPePpBsnP6Sh9i72U7wAUau1Ogb8dHEBXcXsWQkc4QjzR4hQvMno7XFiWAAk3SzGD5I6nWNrOMluoal4YD%2FwMdgvYEtxjlaDvgq%2FLaMA1%2BHVjIzxSJ0O7LjXJH%2F9mCeUvnNnSkeiIkKlUR9Qg6VbLfyofwBgYTCkQEavdFrK07dZMDu84oI%2BVE6Y0GURzJI6KhoJOORn5IbOxYnBByKAw%3D%3D&returnUrl=https://localhost:4200

    2- on calling this url with identity server url getting following error:

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Do you have similar code like below?

    Configure<AppUrlOptions>(options =>
    {
        options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; // "SelfUrl": "https://localhost:44303"
    });
    
  • User Avatar
    0
    shobhit created

    yes as part of "IdentityServerModule" --> ConfigureServices() method

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Please also configure it in the project that calls SendEmailConfirmationLinkAsync.

  • User Avatar
    0
    shobhit created

    Thanks Mailming, Url issue fixed but still getting token invalid issue:

  • User Avatar
    0
    shobhit created

    In Browser console i could see following error: Status 403 Forbidden VersionHTTP/2 Transferred8.81 KB (8.33 KB size)

    we are surely not supporting HTTP/2. I am not sure how HTTP/2 protocol getting used

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    https://support.abp.io/QA/Questions/1400/Email-Confirmation-Token-is-always-Invalid#answer-95c7bf9b-4915-0e3b-296e-39fcbdb8672d

  • User Avatar
    0
    shobhit created

    could not understand which step to follow. Anyway i followed step to "It works for me after SetApplicationName" but still i am getting same issue

  • User Avatar
    0
    shobhit created

    Thanks maliming. Issue solved. Problem lies here:

    if (!hostingEnvironment.IsDevelopment()) { ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); context.Services .AddDataProtection() .PersistKeysToStackExchangeRedis(redis, "EzpandCC-Protection-Keys") .SetApplicationName("MVC"); }

    comment the If statement so that keys can be persited.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Good news.

  • User Avatar
    0
    shobhit created

    Hello maliming, "Email Confirmation" link is working fine for host but not working for tenant. Getting below error:

    https://localhost:44388/Account/EmailConfirmation?userId=faed4fdc-712f-f6b4-95c4-3a010e9dc1fe&tenantId=289f26e2-b3b5-3989-274c-39ff6bddef81&confirmationToken=CfDJ8Hq%2FLQp%2F%2FzRKgTVJkX09EFxA6tONfYjecuq%2FdyDt9%2FlkX1xQOjHA%2BZUrqbrBwdHhaWxKdwq%2BFfTVki5fJm2wPbJSytVZ2zQK9xBpm0a0rYaSsQZmbSgL8SzrrnVSHB7ivEBayxAHiBcOhWzVsAb68vBRm%2BumxUtIGHqTT7twScRt9XBzMVbppfXRlroblrIgVgDHfmUQSnsC%2Fo6d9T0dqXLRO%2BMr%2BMZeqsUEan%2FWA0Xy9vTxXnZOLxahR4Jy0up4TQ%3D%3D&returnUrl=http://localhost:4200

    ApplicationException: Current tenant is different than given tenant. CurrentTenant.Id: , given tenantId: 289f26e2-b3b5-3989-274c-39ff6bddef81

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    This is by design for now.

    You can override it if you needs

  • User Avatar
    0
    shobhit created

    Hello Maliming, It's not working for me i.e. not hitting override method, seems i am missing something.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi shobhit

    You can make the method do nothing

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11