Base solution for your next web application
Open Closed

Could tenants have their own email account? #7257


User avatar
0
mgarcia created

Are tenants able to config their own email account?


22 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    see https://github.com/aspnetzero/aspnet-zero-core/issues/1718#issuecomment-467750138

  • User Avatar
    0
    mgarcia created

    hi! it seems that link is broken.

  • User Avatar
    0
    maliming created
    Support Team

    Notice You can invite anyone to become a member of the ASP.NET Zero organization using their GitHub username. And they can access the ASP.NET Zero private GitHub repositories. Your license plan allows you to add up to 20 users. Right after you add a GitHub user, the user will receive an invitation email. If there is problem receiving the invitation email, alternatively user can visit github.com/orgs/aspnetzero page and accept the invitation.

    https://aspnetzero.com/LicenseManagement

  • User Avatar
    0
    mgarcia created

    Can we talk by Skype?

  • User Avatar
    0
    maliming created
    Support Team

    You still can't access the github page?

  • User Avatar
    0
    mgarcia created

    Yeah, I was able to enter to github page. Right now Im following the idea described there.

    So now I can show the SMTP setting tab on tenants configuration page and all records are being saved to BD succesfully as you can see on this picture:

    But I keep raising an exception It show an url for help about mailkit but I havent been able to send emails. This account is being used on production server and it works. But on development and for tenancy it is not working.

    I checked when it creates the SMTP client and it is using all tenants values as they were save. Maybe you can help me on skype so I can show you.

  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, the error messsage is straight forward.

    5.7.1 Client does not have permission to send as this sender.

    you need to check if the smtp account being used has the permission.

  • User Avatar
    0
    mgarcia created

    Hi!

    Thats what it seems, but that same acc (username and password) on host is working right. But when use with tenant it fails. IEmailSender doesnt work fine when is call from tenant back office test email.

    I event get others errors like this:

    5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 0.35250:0A000B81, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:C01C0000, 1.36674:0E000000, 1.61250:00000000, 1.45378:C51C0000, 1.44866:98010000, 16.55847:420F0000, 17.43559:0000000004020000000000000000000000000000, 20.52176:140F19880000F01F43050000, 20.50032:140F19887017F01F0A00C881, 0.35180:48050000, 255.23226:0A000000, 255.27962:0A000000, 255.27962:0E000000, 255.31418:0A001181, 0.35250:80030400, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:44000000, 1.36674:32000000, 1.61250:00000000, 1.45378:49000000, 1.44866:02000000, 16.55847:B0000000, 17.43559:0000000010030000000000000000000000000000, 20.52176:140F1988000070200A001681, 20.50032:140F1988701710106B050000, 0.35180:0A001781, 255.23226:4800D13D, 255.27962:0A000000, 255.27962:32000000, 255.17082:DC040000, 0.27745:75050000, 4.21921:DC040000, 255.27962:FA000000, 255.1494:7A050000, 0.38698:0F010480, 0.37692:0F010480, 0.44092:0D000100, 0.41232:0D000100, 0.60208:0D000100, 0.37136:0D000100, 0.34608:0D000100, 0.55056:0D000100, 0.42768:0D000100, 0.56112:0D000100, 0.52807:0D000100, 4.33016:DC040000, 7.40748:010000000000010B07000000, 7.57132:000000000000000007000000, 1.63016:32000000, 4.39640:DC040000, 8.45434:B8FE3C50A4E58E47AB4498236AB5842EC7000000, 5.10786:0000000031352E32302E323037332E3030303A4D4E32505231354D42333233323A33613961663663662D616634342D343135322D613733322D64326335306631626666663200201000000000, 255.1750:0A00F136, 255.31418:B1050000, 0.22753:0A002481, 255.21817:DC040000, 4.60547:DC040000, 0.21966:0A002581, 4.30158:DC040000 [Hostname=MN2PR15MB3232.namprd15.prod.outlook.com]

    As I followed the code I can see how the SMTP client succesfully does the auth. Maybe I can show you and that could lead to an idea.

    This same acc on host work fine, on tenant fails.

    I would appreciate your help.

    greetings,

  • User Avatar
    0
    maliming created
    Support Team

    that same acc (username and password) on host is working right. But when use with tenant it fails.

    You can write test code to switch to the tenant call related code, May be reading incorrect mail settings.

    https://aspnetboilerplate.com/Pages/Documents/Multi-Tenancy#switching-between-host-and-tenants.

  • User Avatar
    0
    mgarcia created

    Hi, Im been doing my best to explain my problem but it seems Im not being able to explain myself clearly.

    I already debug all, test the creation of the SMTP client with the correspondent credentials for host and tenant, also I exchanged credentials BUT only Host is able to send emails.

    On tenant it creates the client with his credentials but send fails. I would really appreciate if we can schedule a meeting on skype.

    thx so much.

  • User Avatar
    0
    alper created
    Support Team

    hi,

    If it works on production and doesn't work on development, it means there's a firewall/network setting for production that sets as "safe" that server "MN2PR15MB3232.namprd15.prod.outlook.com".

    5.7.1 Client does not have permission to send as this sender.

  • User Avatar
    0
    mgarcia created

    Hi,

    What I meant is this... I got mails credentials lets call it "A" working on Production enviroment.

    So I copied those credentials and used them on Development enviroment, on Host SMTP configuration, and they work fine.

    But those credentials "A" doent work on tenant. Later I created a new mail account lets call it "B", I set it up on the Host in development and credentials "A" and "B" works as expected, but any of them works on Tenant. I follow up the code with debug and Tenant is getting the right values from DB, but it is something weird. Thats why I would like to show you guys.

  • User Avatar
    0
    mgarcia created

    maliming or alper?

  • User Avatar
    0
    alper created
    Support Team

    it's related to your computer's network settings. If you have installed an anti-virus software, try disabling it.

    Why don't you try to test your SMTP settings with a 3rd party application. Use SMTPProber to send a test email. You will see if it's related to the code or environment. Download it from http://www.alexnolan.net/software/SMTPProber.exe

    Also see these:

    • https://docs.microsoft.com/en-us/Exchange/mail-flow-best-practices/how-to-set-up-a-multifunction-device-or-application-to-send-email-using-office-3?redirectSourcePath=%2fen-us%2farticle%2fHow-to-set-up-a-multifunction-device-or-application-to-send-email-using-Office-365-69f58e99-c550-4274-ad18-c805d654b4c4#configconnector
    • https://stackoverflow.com/questions/12081159/5-7-1-client-does-not-have-permission-error-while-sending-email-from-code
    • https://stackoverflow.com/questions/7269174/net-smtp-client-client-does-not-have-permissions-to-send-as-this-sender
  • User Avatar
    0
    mgarcia created

    Hi alper,

    "Why don't you try to test your SMTP settings with a 3rd party application."

    Ive been writing that SMTP settings work fine, I have 2 SMTP accounts which I have tested on HOST and they WORK fine.

    When I tried any of this account on tenants they FAIL.

    I can show you if you really want to help me.

  • User Avatar
    0
    mgarcia created

    added evidence both email accounts are working...

  • User Avatar
    0
    alper created
    Support Team

    I think your SMTP server requires authentication.

    try
    {
      using (var client = new SmtpClient())
      {
        client.ServerCertificateValidationCallback = ValidateRemoteCertificate;
        client.Connect(host, 465, true);
    
        client.AuthenticationMechanisms.Remove("XOAUTH2");
    
        // Note: only needed if the SMTP server requires authentication
        client.Authenticate(login, password);
        
        //send mail.....
        
        client.Disconnect(true);  
       
      }
    
    
    }
    catch(Exception ex) { 
    
    }
    
  • User Avatar
    0
    mgarcia created

    Hi!

    The code is already doing that on Core Project -> MasterPagoCoreModule.cs

        public class Office365SmtpBuilder : IMailKitSmtpBuilder
        {
            private readonly ISmtpEmailSenderConfiguration _smtpEmailSenderConfiguration;
    
            public Office365SmtpBuilder(ISmtpEmailSenderConfiguration smtpEmailSenderConfiguration)
            {
                _smtpEmailSenderConfiguration = smtpEmailSenderConfiguration;
            }
    
            public virtual SmtpClient Build()
            {
                var client = new SmtpClient();
    
                try
                {
                    ConfigureClient(client);
                    return client;
                }
                catch
                {
                    client.Dispose();
                    throw;
                }
            }
    
            protected virtual void ConfigureClient(SmtpClient client)
            {
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;  //added this line
    
                client.Connect(
                    _smtpEmailSenderConfiguration.Host,
                    _smtpEmailSenderConfiguration.Port,
                    _smtpEmailSenderConfiguration.EnableSsl
                );
    
                client.AuthenticationMechanisms.Remove("XOAUTH2");  //added this line
                var userName = _smtpEmailSenderConfiguration.UserName;
                if (!userName.IsNullOrEmpty())
                {
                    client.Authenticate(
                        _smtpEmailSenderConfiguration.UserName,
                        _smtpEmailSenderConfiguration.Password
                    );
                }
            }
        }
    

    Each Time the method SendTestEmail() in SettingAppServiceBase class is invoke it creates the SMTP client with the corresponding credentials.

    namespace DACOR.Masterpago.Configuration
    {
        public abstract class SettingsAppServiceBase : MasterpagoAppServiceBase
        {
            private readonly IEmailSender _emailSender;
    
            protected SettingsAppServiceBase(
                IEmailSender emailSender)
            {
                _emailSender = emailSender;
            }
    
            #region Send Test Email
    
            public async Task SendTestEmail(SendTestEmailInput input)
            {
                try
                {
                    await _emailSender.SendAsync(
                        input.EmailAddress,
                        L("TestEmail_Subject"),
                        L("TestEmail_Body")
                    );
                }
                catch (System.Exception e)
                {
    
                    throw e;
                }
            }
    
            #endregion
        }
    }
    
  • User Avatar
    0
    alper created
    Support Team

    check that _smtpEmailSenderConfiguration.UserName has value

  • User Avatar
    0
    alper created
    Support Team

    if we can connect to your smtp host, send us your smtp host credentials to [email protected]

  • User Avatar
    0
    mgarcia created

    Hi Alper!

    "check that _smtpEmailSenderConfiguration.UserName has value"

    Thats something Ive been trying to explain in this topic for a while, I already checked that values for Host and Tenant, it has the corresponding value for each account ( Host take his own credentials and Tenant also his own credentials) But when it comes to send the email it fails.

    I think the problem is being occured by IEmailSenderConfiguration interface and the field DefaultFromAddress that is only a get and take the value from Host Account, it cannot be replace or changed.

    I'll send you the credentials to the given email.

  • User Avatar
    0
    alper created
    Support Team

    hi,

    we have replied your email.