MailKit it's worked on local pc only, but don't work on live server (2016) on azure.

Created on 20 Mar 2017  路  9Comments  路  Source: jstedfast/MailKit

MailKit it's worked on local pc only, but don't work on live server (2016) on azure.
When i tested on windows 10 email send is correct, but when we try to deploy to production server
on Azure we can't send email.

I don't make sure IIS on the server block the email service ?
We tried to enable SMTP on server but it's not help.

screen shot 2560-03-20 at 1 55 54 pm

screen shot 2560-03-20 at 2 51 11 pm

screen shot 2560-03-20 at 3 59 27 pm

Best,
Uthen

question

Most helpful comment

You need to allow access to the Gsuit Gmail account, because, google blocks the mail from different IP's.

https://accounts.google.com/DisplayUnlockCaptcha

All 9 comments

Sample code we used:

public class EMailSender
{
public async Task SendEmailByThread(string sSubject, string sHtmlBody,
string sFromEmail, string sToEmail, string sFromName, string sToName,
string sAuthenPassword, int nPort, string sSMTP)
{
var message = new MimeMessage();
message.From.Add(new MailboxAddress(sFromName, sFromEmail));
message.To.Add(new MailboxAddress(sToName, sToEmail));
message.Subject = sSubject;

        var bodyBuilder = new BodyBuilder();
        bodyBuilder.HtmlBody = sHtmlBody;
        message.Body = bodyBuilder.ToMessageBody();

        using (var client = new SmtpClient())
        {
            await client.ConnectAsync(sSMTP, nPort, false);

            // Note: since we don't have an OAuth2 token, disable
            // the XOAUTH2 authentication mechanism.
            client.AuthenticationMechanisms.Remove("XOAUTH2");
            await client.AuthenticateAsync(sFromEmail, sAuthenPassword);

            client.Send(message);
            client.Disconnect(true);
        }
    }
}

relate on this number or not ? https://github.com/jstedfast/MailKit/issues/393

GMail blocks logins from unknown IP addresses. You need to login to your GMail account from your azure server first. Then it will work.

@jstedfast unbelievable it's worked wowwwwwwww and cool.
You save my day & night 馃憤

you're welcome!

@jstedfast It's worked good on azure, but it's not work on amazon ec2 ?

You need to allow access to the Gsuit Gmail account, because, google blocks the mail from different IP's.

https://accounts.google.com/DisplayUnlockCaptcha

@jstedfast unbelievable it's worked wowwwwwwww and cool.
You save my day & night 馃憤

How did you logged in from Azure?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rhagh picture rhagh  路  5Comments

dbogatov picture dbogatov  路  7Comments

atiqi36 picture atiqi36  路  7Comments

portal7 picture portal7  路  3Comments

shayazm picture shayazm  路  3Comments