Forums

Using SMTP as a Free User

[admin update 2013-10-28: see the wiki section on email/smtp]

Hi, I am on a free user account and have encountered a problem with my program. Basically the program is a questionnaire that takes the answers of the user and transfers them to an Excel document. After this is done, though, I have the program email using gmail. At this point, I am told that "The network is unreachable." Is it possible at all to email as a free user?

Gmail's servers should work -- here are the settings that would work in Django:

EMAIL_HOST = "smtp.gmail.com"
EMAIL_HOST_USER = "yourusername@gmail.com"
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

If you're using something that you're sure is the same, could you post it here (without the username and password, of course!)

I don't believe I'm using Django... This is just a program i wrote in Python 2.7 and i just uploaded it here. I'll post both the function and the place in main where the function is called:

def send_mail(send_from, send_to, subject, text, login, password, files=[], server = 'smtp.gmail.com:587'): '''A function to connect to a gmail account and send an email with the attached, fully filled out DRQ.''' assert type(send_to)==list assert type(files)==list

msg = MIMEMultipart()
msg['From'] = send_from
msg['To'] = COMMASPACE.join(send_to)
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject

msg.attach( MIMEText(text) )

for f in files:
    part = MIMEBase('application', "octet-stream")
    part.set_payload( open(f,"rb").read() )
    Encoders.encode_base64(part)
    part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
    msg.attach(part)

smtp = smtplib.SMTP(server)
smtp.starttls()
smtp.login(login, password)
smtp.sendmail(send_from, send_to, msg.as_string())
smtp.close()

send_from = 'prattdrqdonotreply@gmail.com' send_to = ['scboxdesign@gmail.com'] subject = itemnum if(sendEmail == 'Y' or sendEmail == 'y'): text = raw_input('Write anything that you would like to include in the body of your email: ') files = [drqsave] login = 'gmailusername' password = 'password'

if(sendEmail == 'Y' or sendEmail == 'y'):
    send_mail(send_from, send_to, subject, text, login, password, files)

Mind you, I am not a professional coder by any means.. I have just finished my second comp sci class in college and we learned python so i only have a basic understanding thus far.

Hmm, that looks at first glance like it should work. Is this running as a web application?

No sir, i believe it is running from the consoles tab. It works fine on this end, but i tried to share the console with another user, and the other user could not get the email to work.

Ah, got it. It looks like Gmail's SMTP server has changed its IP address under our feet (it happens from time to time, we're working on a fix). I've updated the system with the new address, so if you try again now it should work.

It does! Thank you so much for the help!

No problem, glad we could get it working :-)