I want to generate email contents on the fly and send email from a Gmail account using Python from an EC2 server. It works fine when I do it on localhost, but when I run the same code on my EC2, it doesn't work...
Here is my code:
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
msg = MIMEMultipart()
part = MIMEApplication(file("<pathtopdf>").read())
part.add_header('Content-Disposition', 'attachment; filename="<nameofpdf.pdf>"')
msg.attach(part)
msg['From'] = "<username>@gmail.com"
msg['To'] = "<username>@gmail.com"
msg['Subject'] = "Hello PDF"
import smtplib
server = smtplib.SMTP('smtp.gmail.com',587) #port 465 or 587
server.ehlo()
server.starttls()
server.ehlo()
server.login(<login info params>)
server.close()
Is there anyway to do this without using Amazon SES? I only have to send an email upon customer request, and I just have to generate a quick PDF based on customer input and send an email to the customer at the email they specify to send to... it's a very simple operation and the hoops I have to jump through are getting a tad frustrating.