Sending email using smtp gmail server from Amazon EC2 instance

若如初见. 提交于 2019-12-22 09:46:27

问题


I have a gmail for business emailId and would like to use it for sending out messages to my clients. I am using smtp.gmail.com to send out messages from an asp.net mvc application. This works fine on my localhost. But when I deployed the code to Amazon EC2, the functionality broke. I searched and found that EC2 IPs are blackisted by google. How should I fix this? I read that one way is to use Amazon SES, but can anyone tell how does it work? Is it just a verification policy enforcement thing and does it support sending out email from the said gmail account? Is there any other workaround?

Edit 1: As suggested I have contacted Amazon to provide production access. It is in process.

Meanwhile, I am seeing that I am able to send mails from my application. These are my settings -

WebMail.SmtpServer = "smtp.gmail.com";
WebMail.SmtpPort = 587;
WebMail.EnableSsl = true;
WebMail.UserName = "me@example.com";
WebMail.From = "me@example.com";
WebMail.Password = "MyPassword";
WebMail.SmtpUseDefaultCredentials = false;

Is there a reason why suddenly it is working. Is this intermittent or can I move on to using this as such?


回答1:


SES is the solution for this problem, and then good thing is, unless you are sending 10's of thousands of emails it will only cost you pennies to do - it will allow you to send an email, and make it come from (or appear to come from) your gmail account.

First step is to verify to SES that you own/control the email address you want to send from - that can be done by clicking on a link in an email they send to that address, or else adding some TXT entries to your DNS settings. If you control the domain, I prefer to use the DNS method so that I can verify the entire domain for sending emails, not just the one account - then you can do things like send from 'sales@mydomain.com', 'billing@mydomain.com' etc w/out having to verify each email address individually.

Once you account is verified, sending email from SES using the SMTP option is exactly the same as sending it thru any other SMTP server - use the SMTP server name, username and password from amazon, and away you go.

Very easy, very inexpensive and emails are sent very fast.

Be aware there are limits by default - I believe 5/second and 10,000/month by default - but that can be upped if you have a legitimate need.

Also, once your account is setup with SES, you are not limited to sending your emails just from EC2 instance, you can use it anywhere - for example my outlook email, my mac and my iphone all use SES as my SMTP provider.




回答2:


I was actually able to send an email using an EC2 instance. Try editing your SMTP Server to ssl://smtp.gmail.com



来源:https://stackoverflow.com/questions/28656925/sending-email-using-smtp-gmail-server-from-amazon-ec2-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!