Sending email through Python -


#!/usr/bin/python import smtplib email.mime.multipart import mimemultipart email.mime.text import mimetext email.mime.base import mimebase email import encoders fromaddr = "sender mail id" toaddr = "receiver mail id" msg = mimemultipart() msg['from'] = fromaddr msg['to'] = toaddr msg['subject'] = "test" body = "test mail" msg.attach(mimetext(body, 'plain')) filename = "foo.txt" attachment = open(r"f:\python\foo.txt", "rb") part = mimebase('application', 'octet-stream') part.set_payload((attachment).read()) encoders.encode_base64(part) part.add_header('content-disposition', "attachment; filename= %s" % filename) msg.attach(part) server = smtplib.smtp('smtp.gmail.com', 587) server.starttls() server.login(fromaddr, "password") text = msg.as_string() server.sendmail(fromaddr, toaddr, text) server.quit() 

this script working fine when running on local system on running on private network giving me error.

oserror: [win error 10051] socket operation attempted unreachable network.

you may want if have access private network smtp.gmail.com on port 587

the private network admin may have setup network block outbound traffic on port 587

try:

telnet smtp.gmail.com 587 

if unreachable network error network issue.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -