2

I am using " Mailkit " to send emails from a dot net core console application (using smtp). It works when i run the application in my local machine and I receive emails.

However, when i deployed as an azure webjob, It does not send emails. I could see the job completes successfully and no errors logged. BUT i do not receive emails

I am just wondering how it works in local machine and it does not while run in azure.

Update:

Based on comments below, trying to be specific. can someone confirm if you were able to use Mailkit and an organizational smtp server(no public domains) & email account to send emails from an azure webjob ? or else please suggest what should be a working setup. thanks!

blogs4t
  • 2,329
  • 5
  • 20
  • 33
  • Are you sure the emails aren't being caught in a spam trap? – jstedfast Aug 01 '17 at 17:49
  • I just tested sending mail from my WebJob and working fine on my side. Which mail server did you use? Sometimes the mail server will reject the sending mail request from a new client or different time zone(note that Azure WebJob use UTC±00:00 as the default time zone). – Amor Aug 02 '17 at 05:31
  • @jstedfast I am using my company email address. the smtp server also belongs to my organization. Do you think the cause could be Mailkit? should i use a different smtp library that would work in an azure hosted env? – blogs4t Aug 02 '17 at 14:45
  • @Amor pls refer to my earlier comment. I am using smtp & email provided by my organization. Are you using Mailkit by the way? or do you use a different provider? I could see you mentioned yours is an azure webjob.. – blogs4t Aug 02 '17 at 14:46
  • I guarantee that the problem is not with MailKit. Most likely the server is trapping the message for some reason - like Amor said, you might need to authenticate on your web server via a web browser to get the smtp server to recognize your web server. – jstedfast Aug 02 '17 at 14:48
  • @jstedfast I see, you might be correct, at present i am using the default port 25 which does not require authentication. i will try out with authentication and get back. – blogs4t Aug 02 '17 at 14:52
  • Meanwhile, @Amor could you please post your code that works.? I'm interested in knowing which smtp provider you are using. that works with your webjob. thanks! – blogs4t Aug 02 '17 at 14:53
  • I was using Google mail server to send mail. I will post my sample code when I back to office. – Amor Aug 02 '17 at 15:50
  • If you are using GMail, you *definitely* need to authenticate in a browser before you can authenticate in MailKit because GMail requires web login from an IP before you can login via SMTP. – jstedfast Aug 02 '17 at 18:19

1 Answers1

0

can someone confirm if you were able to use Mailkit and an organizational smtp server(no public domains) & email account to send emails from an azure webjob ? or else please suggest what should be a working setup. thanks!

No public domain means that we can't access the smtp server through the internet. As a workaround, you could save the mail information to a Azure Queue Storage from the WebJob and writing a new application and publish it to your internal network. In your new application, you could get the information from Azure queue storage and send the mail from your internal network.

Amor
  • 8,325
  • 2
  • 19
  • 21