I'm having a test suite in python and i would like to email the result through my company server. I used a similar code but the code seems to be hung while waiting for a response from server during socket.connect() call. I traced the code and found that it enters the connect() method in smtplib.py and from there it enters readline() method in socket.py......this is where is waits forever for response from mail server.
If I do a "netstat -a" on DOS prompt, I can see that connection is ESTABLISHED between mail server and the connection I initiated via python script.
FYI: if I do a ping MYSERVER, I can see the response, So I am sure, the mail server on our network is responding!
import os import smtplib import mimetypes from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email.MIMEAudio import MIMEAudio from email.MIMEImage import MIMEImage from email.Encoders import encode_base64 def sendMail(subject, text): UserName = 'firstname.lastname@example.org' UserPwd = 'mypassword' recipient = 'email@example.com' msg = MIMEMultipart() msg['From'] = UserName msg['To'] = recipient msg['Subject'] = subject msg.attach(MIMEText(text)) mailServer = smtplib.SMTP('192.168.178.22',1352) mailServer.login(UserName, UserPwd) mailServer.set_debuglevel(1) mailServer.sendmail(UserName, recipient, msg.as_string()) mailServer.quit() print('Sent email to %s' %(recipient)) if __name__ == '__main__': sendMail('hi','hello how are u')
Any comments would be of great help....thank you