2
#!/usr/bin/python
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from 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 is working fine when I running on my local system but on running on private network its giving me a error.

OSError: [Win Error 10051] A socket operation was attempted to an unreachable network.

1 Answer 1

1

You may want to look into if you have access from your private network to smtp.gmail.com on port 587

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

Try:

telnet smtp.gmail.com 587

If you get an unreachable network error its definitely a network issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.