Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Unclear on argument passing to "sendmail'

Reply
Thread Tools

Unclear on argument passing to "sendmail'

 
 
John Draper
Guest
Posts: n/a
 
      08-21-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
 
Reply With Quote
 
 
 
 
Tim Roberts
Guest
Posts: n/a
 
      08-22-2006
John Draper <> wrote:
>
>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>?


Tim William's answer is not exactly correct. The host you specify in the
smtplib.SMTP constructor should NOT be the MX record for any of the
recipients. You should never have to look up MX records yourself.

Instead, you should specify your ISP's outgoing mail host. In your
particular case, you should specify "mail.webcrunchers.com". That server
will do the MX record lookups, and distribute the message to all of the
places it needs to go, using as many SMTP conversations as are required.

Remember that a single call to smtplib.SMTP.sendmail can send to multiple
recipients. Each of them has to have its own SMTP connection. That's the
job of mail.webcrunchers.com: it queues your message, and sends it to each
recipient individually.

If your message is being sent to exactly one person, then you CAN look up
the MX host and send it directly, but there are more and more cases where
that won't work. Many corporate SMTP servers are now rejecting mail that
comes from DSL and cable modem IP addresses, as an anti-spam measure.
--
- Tim Roberts,
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
 
 
 
Tim Williams
Guest
Posts: n/a
 
      08-22-2006
On 22/08/06, Tim Roberts <> wrote:
> John Draper <> wrote:


Hi Tim

> Tim William's answer is not exactly correct. The host you specify in the
> smtplib.SMTP constructor should NOT be the MX record for any of the
> recipients. You should never have to look up MX records yourself.


actually, I said:
this will be a server from the recipient's domain's mx records (or
your ISP server).

However it really depends on the use-case, relaying through another
server will give you no control over bad addresses, you have to wait
for bounces from the recipient's server, or conversely the ISP server
can give fails 4xx & 5xx for valid addresses. The ISP may only
accept email addressed from their local domains, and you may be
breaking their TOCs or AUP and get blocked.

On the flip side, some ISPs block outbound port 25 except through
their servers, or transparent proxy port 25, so Direct MX is
unusable.

Blacklists are hit and miss, even large ISPs can get listed. If you
are on a "clean" range then it shouldn't matter, you can look up your
IP on various blacklists to see if it is affected. Also Many fixed IP
addresses don't have valid PTRs so they can fail as often as dynamic
IP addresses which usually do have valid PTRs

John Draper <> wrote:

> Hmmm - the problem I have is if I knowingly
> put in a bad recipient, and try to send to a
> unknown user, I get all appearances that
> the mail went through.


Yes this will happen if you use a relay server.

> Ok, so If I already have a MX hostname
> of "mail.myhost.com", then I would put
> into my "to_email"... <myusername>@myhost.com for


Yes, if you just used username the server wouldn't know which domain
the email was being sent to and therefore how to route it.

> By the way, I'm sending this mail to a "sms"
> gateway to a cellular provider, so the
> username is their phone number.


If you only ever send to this gateway then you might as well try MX
records, you will have more control, but you will need to manage
queueing yourself for temporary failures, or you may decide that if
you get a temporary failure (4xx) to just fire the email off to your
ISP server and let them deal with it.


> But
> (sigh), these providers don't appear
> to tell me if I put in a bogus phone number.


Unfortunately not all mail servers will fail an invalid address even
if they aren't relaying the email. But in this case the SMS
"gateway" is probably relaying to a backend system for the SMSc and
will accept any address with a valid domain part.

HTH
 
Reply With Quote
 
John Draper
Guest
Posts: n/a
 
      08-22-2006
I will respond to part of this, although it wasn't directed to me.

Tim Williams wrote:

> However it really depends on the use-case, relaying through another
> server will give you no control over bad addresses, you have to wait
> for bounces from the recipient's server, or conversely the ISP server
> can give fails 4xx & 5xx for valid addresses. The ISP may only
> accept email addressed from their local domains, and you may be
> breaking their TOCs or AUP and get blocked.


I usually will have no problem with this, and for one reason is because
before I add a new ISP to my spam reporting queue, I establish a
direct SMTP connection with the ISP's "abuse" email server to confirm
the Email is good. I get a lot more then my share of BAD or Bogus Emails
listed in some of these whois queries I get.

>
> On the flip side, some ISPs block outbound port 25 except through
> their servers, or transparent proxy port 25, so Direct MX is
> unusable.


I send all of my spam reports through a commercial T1 link.. I made
the bad mistake of sending my spam reports directly from my ComCrap
(err - comcast) account, and my service got hosed for a day or so.

>> Hmmm - the problem I have is if I knowingly
>> put in a bad recipient, and try to send to a
>> unknown user, I get all appearances that
>> the mail went through.

>
>
> Yes this will happen if you use a relay server.


yea - I know....

>
>> Ok, so If I already have a MX hostname
>> of "mail.myhost.com", then I would put
>> into my "to_email"... <myusername>@myhost.com for

>
>
> Yes, if you just used username the server wouldn't know which domain
> the email was being sent to and therefore how to route it.
>
>> By the way, I'm sending this mail to a "sms"
>> gateway to a cellular provider, so the
>> username is their phone number.

>
>
> If you only ever send to this gateway then you might as well try MX
> records, you will have more control, but you will need to manage
> queueing yourself for temporary failures, or you may decide that if
> you get a temporary failure (4xx) to just fire the email off to your
> ISP server and let them deal with it.


I'm currently exploring a number of different options at this time,
including giving the customer an option to go back and re-visit their
order page and get an update in the event the message bounces.

I'm setting up a special "reply_to" address which I use to collect
bounces, and customer's asknowledgement they got the content.
Once I get the Ack from the customer, I'll KNOW they got the product.

>
>
>> But
>> (sigh), these providers don't appear
>> to tell me if I put in a bogus phone number.

>
>
> Unfortunately not all mail servers will fail an invalid address even
> if they aren't relaying the email.


I haven't really run into a lot of them, but I've had NO experience with
SMTP->SMS gateways.

> But in this case the SMS
> "gateway" is probably relaying to a backend system for the SMSc and
> will accept any address with a valid domain part.


I already know that Sprint does this, but (sigh) I don't even get the
bounces if
I re-direct them to a specific Email box.... DARN - Foiled again.

John
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use a passing argument(returned argument)? ±è ÁØ¿µ Ruby 7 11-27-2008 03:53 AM
Passing a function as an argument and using the evaluated functionas an argument User1014 Javascript 1 11-30-2006 12:13 PM
Still unclear Irfaan Wahid MCSD 3 02-24-2005 12:14 PM
Argument-per-argument Passing Trans Ruby 3 01-26-2005 05:58 PM
Unclear on the concept... kj XML 2 04-12-2004 02:49 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57