Unclear on argument passing to "sendmail'

John Draper lists at webcrunchers.com
Mon Aug 21 17:31:26 EDT 2006


In "smtplib" module, the "sendmail" method of function is to be passed a 
host, but it is the Domain name
for the SMTP Server as gotten from the "dig" command?   IE:   dig -tMX 
would give me the SMTP
server.   In my code I have:

try:
    print "Sending message to host: %s" % mailHost
    server=smtplib.SMTP(mailHost)
    server.sendmail(reply_email,email,body)
    server.quit()
except:
    print "Uunable to send"

Is mailHost like "mail.t-mobile.com" which I get from the MX record for 
a given domain?
But also,  is the "email" just the mail account,  ie:  the username?   
without the @<domain>?

I need to be able to query the mail server?   Also,  I want to be able 
to handle
the "SMTPRecipientsRefused" exception.   What is the proper syntax for 
handling
this?

Do I do it like this?

try:
    print "Sending message to host: %s" % mailHost
    server=smtplib.SMTP(mailHost)
    server.sendmail(reply_email,email,body)
    server.quit()
except SMTPRecipientsRefused:
    print "Recipient refused"

Is that the right syntax?   I have severe problems with not enough 
example code.

John

I



More information about the Python-list mailing list