Jump to content

Recommended Posts

Posted

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: python email script

 

The code is as follow is:

 

>import smtplib

smtpserver = 'mail.example.com'
AUTHREQUIRED = 0 # if you need to use SMTP AUTH set to 1
smtpuser = ''  # for SMTP AUTH, set SMTP username here
smtppass = ''  # for SMTP AUTH, set SMTP password here

RECIPIENTS = ['user@example.com']
SENDER = 'jimbob@example.net'
mssg = open('mssg.txt', 'r').read()

session = smtplib.SMTP(smtpserver)
if AUTHREQUIRED:
session.login(smtpuser, smtppass)
smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)

if smtpresult:
errstr = ""
for recip in smtpresult.keys():
	errstr = """Could not delivery mail to: %s

Server said: %s
%s

%s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)
raise smtplib.SMTPException, errstr

 

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.

 

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.

 

Anyone have any suggestions as to what I can do to get this script to work and not get rejected by TCH smtp server?

 

Thanks.

Posted

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!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...