Email Script

liunx

Guest
I am trying to write a script to send emails using python. It is not intended that this script be uploaded to web, but instead is part of a program that I am messing around with that will be set up to send an email. I want the script to automatically send email from an email address account on my tch domain. I came accross the following example of such a script at this link: <a href="http://www.thinkspot.net/sheila/article.php?story=20040822174141155" target="_blank">python email script</a><br /><br />The code is as follow is:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->import smtplib<br /><br />smtpserver = 'mail.example.com'<br />AUTHREQUIRED = 0 # if you need to use SMTP AUTH set to 1<br />smtpuser = ''  # for SMTP AUTH, set SMTP username here<br />smtppass = ''  # for SMTP AUTH, set SMTP password here<br /><br />RECIPIENTS = ['[email protected]']<br />SENDER = '[email protected]'<br />mssg = open('mssg.txt', 'r').read()<br /><br />session = smtplib.SMTP(smtpserver)<br />if AUTHREQUIRED:<br />    session.login(smtpuser, smtppass)<br />smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)<br /><br />if smtpresult:<br />    errstr = ""<br />    for recip in smtpresult.keys():<br />        errstr = """Could not delivery mail to: %s<br /><br />Server said: %s<br />%s<br /><br />%s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)<br />    raise smtplib.SMTPException, errstr<!--c2--></div><!--ec2--><br /><br />I inputed the proper infomation (sender, recipirnt, smtp info,etc), and compiled the script. However when I run it I get a "Error 550 Administrative Prohibition." In googling that error number and description, it seems that this might have something to do with TCH's SMTP server blocking my attempt to send a message.<br /><br />I am trying this script from a desktop on which I have loaded Ubuntu (linux distribution). If I send an email (from and to same addresses as used in script) using Evolution email client (like outlook), everything works fine; if I send from XP machine (same addresses) work fine.<br /><br />Anyone have any suggestions as to what I can do to get this script to work and not get rejected by TCH smtp server?<br /><br />Thanks.<!--content-->
Think I solved this. The above script does not generate any headers ("to", "from" or "subject"). Apparently tch's smtp server rejects that the email if it does not have headers. If you add same to the text file that comprises the body of the email, it works!<!--content-->
Glad you solved it. Without the headers you cannot validate to send. You cannot send email through the server without validating.<!--content-->
 
Back
Top