473,569 Members | 3,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

smtplib does not send to all recipients

Here is a snippet of code which does not send to all recipients.
However, it also does not inform me of this error. My suspicion is
that this only fails for users with longer usernames. The two I seem
to regularly fail on have 9 and 11 characters respectively. Most users
have names <= 8 characters.

domain = "myDomainHere.c om"
admin = "d123456@%s " % domain
adminFull = "Full Name Here <%s>" % admin
def mailMsg(text, subject, sender, recipients):
# From: and To: headers at the start!
if not sender:
sender = adminFull
elif not sender.endswith (domain):
sender += ("@" + domain)
addresslist = []
for name in recipients:
if not name.endswith(d omain):
name += ("@" + domain)
addresslist.app end(name)
msg = "From: %s\r\nTo: %s\r\n" % (sender, ", ".join(addressl ist))
msg += "Subject: %s\r\n\r\n" % subject
for line in text.split('\n' ):
msg += "%s\r\n" % line.rstrip()

try:
server = smtplib.SMTP('l ocalhost')
server.set_debu glevel(0)
failures = server.sendmail (sender, recipients, msg)
if len(failures):
safeMailMsg("%s \n\n%s" % (failures, msg),
"ttLadder: sent with failures", [admin])
server.quit()
except smtplib.SMTPSen derRefused, sndErr:
safeMailMsg("%s \n\n%s" % (sndErr, msg),
"ttLadder: sender refused", [admin])
except smtplib.SMTPRec ipientsRefused, rcpErr:
safeMailMsg("%s \n\n%s" % (rcpErr, msg),
"ttLadder: recipients refused", [admin])
except Exception, xcp:
safeMailMsg("%s \n\n%s" % (xcp, msg),
"ttLadder: other exception", [admin])
return

The safeMailMsg() routine uses os.system("mail ..."). It works but it
is not sending me any error in this case.

When I test by sending the same mail to myself (7 characters) and a
long name (11 characters), I receive the e-mail but the other user does
not. However, the header in the mail looks correct and if I do a
"Reply-all" it will happily send the mail to both of us.

Is this a known problem with older versions of smtplib? I'm using
Python 2.2.2.

Thanks,
David

Jul 18 '05 #1
8 2576
I changed debuglevel to 1 and looked at the response on the recipient
names. They are BOTH accepted, but still only my id (d123456) receives
the e-mail. The long id (d1234567890) never gets the e-mail. Here is
the excerpt of the exchange.

send: 'mail FROM:<d1*****@m yDomainHere.com > size=160\r\n'
reply: '250 2.1.0 <d1*****@myDoma inHere.com>... Sender ok\r\n'
reply: retcode (250); Msg: 2.1.0 <d1*****@myDoma inHere.com>... Sender
ok
send: 'rcpt TO:<d123456>\r\ n'
reply: '250 2.1.5 <d123456>... Recipient ok\r\n'
reply: retcode (250); Msg: 2.1.5 <d123456>... Recipient ok
send: 'rcpt TO:<d1234567890 >\r\n'
reply: '250 2.1.5 <d1234567890>.. . Recipient ok\r\n'
reply: retcode (250); Msg: 2.1.5 <d1234567890>.. . Recipient ok

Jul 18 '05 #2
dc******@gmail. com wrote:
I changed debuglevel to 1 and looked at the response on the recipient
names. They are BOTH accepted, but still only my id (d123456) receives
the e-mail. The long id (d1234567890) never gets the e-mail. Here is
the excerpt of the exchange.

send: 'mail FROM:<d1*****@m yDomainHere.com > size=160\r\n'
reply: '250 2.1.0 <d1*****@myDoma inHere.com>... Sender ok\r\n'
reply: retcode (250); Msg: 2.1.0 <d1*****@myDoma inHere.com>... Sender
ok
send: 'rcpt TO:<d123456>\r\ n'
reply: '250 2.1.5 <d123456>... Recipient ok\r\n'
reply: retcode (250); Msg: 2.1.5 <d123456>... Recipient ok
send: 'rcpt TO:<d1234567890 >\r\n'
reply: '250 2.1.5 <d1234567890>.. . Recipient ok\r\n'
reply: retcode (250); Msg: 2.1.5 <d1234567890>.. . Recipient ok


In which case the Python is working perfectly correctly and you need to
take the matter up with whoever runs the SMTP server. Are you sure the
address is actually valid?

regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/

Jul 18 '05 #3

dccarson> I changed debuglevel to 1 and looked at the response on the
dccarson> recipient names. They are BOTH accepted, but still only my id
dccarson> (d123456) receives the e-mail. The long id (d1234567890)
dccarson> never gets the e-mail. Here is the excerpt of the exchange.

...
dccarson> reply: '250 2.1.5 <d123456>... Recipient ok\r\n'
...
dccarson> reply: '250 2.1.5 <d1234567890>.. . Recipient ok\r\n'

Sorta makes it look like it's not an smtplib problem, doesn't it? ;-)

Skip
Jul 18 '05 #4
That seems reasonable. However, using the 'mail' utility I can deliver
the same mail successfully. I assume mail is using sendmail under the
covers, which is doing the same negotiation with the same SMTP server?

Jul 18 '05 #5
dc******@gmail. com wrote:
That seems reasonable. However, using the 'mail' utility I can deliver
the same mail successfully. I assume mail is using sendmail under the
covers, which is doing the same negotiation with the same SMTP server?
The facts would appear to suggest that both sources are accepted by the
local SMTP server - as long as you are positive both chains are indeed
contacting the same server. Ethereal could show you this.

A possible scenario would be that the downstream SMTP chain is somehow
discriminating against the Python-originated messages. Logs should give
evidence here.

So, unless it's a simple typo and you are using different (email or SMTP
server) addresses that you think are the same, see my original response,
which included
and you need to take the matter up with whoever runs the SMTP server. Are you sure the address is actually valid?


Evidence for and against? These things are a pain, but with patience you
can usually track them down. You could try explaining to a stuffed toy,
or a sock on your hand, exactly why there can't be anything wrong with
your code. My wife's bears are very forbearing [n.p.i.]. Whatever it
takes to break the perceptual barrier.

We now return you to your regular episode of scheduled tasks ...

regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/

Jul 18 '05 #6
OK, I've discovered the lost messages, but I'm still slightly confused
as to why they ended up there. The messages were being delivered to
the local machine, box1.domain.com , even though I was addressing them
to <user>@domain.c om.

My past experience with smtp mail has been that if I addressed the
domain explicitly, the mail would not stop at the local machine. This
is in fact why the 'mail' utility is working. If I use 'mail' to mail
something to <user> with no domain, it goes to the local machine, as I
would expect, but addressed to <user>@domain.c om, it goes to the
corporate server.

So why does smtplib deliver to box1.domain.com ? If the local smtp at
box1.domain.com is configured such that this is correct behavior, I
guess I'd expect the 'mail' utility to do the same thing when handling
address <user>@domain.c om.

By the way, the long vs. short usernames was a red herring. Those with
..forward files were getting their mail.

Jul 18 '05 #7
dc******@gmail. com wrote:
OK, I've discovered the lost messages, but I'm still slightly confused
as to why they ended up there. The messages were being delivered to
the local machine, box1.domain.com , even though I was addressing them
to <user>@domain.c om.


The address is irrelevant with SMTP. What matters is
what server you connect to, and how it is configured
to handle the envelope you give it.

Mail forwarders ought to query a DNS for the "MX"
record (on Linux, "dig domain.com mx" for that info)
and forward the mail to one of the specified mail
exchangers for that domain, regardless of what
server you actually connected to for the initial
delivery.

Not sure this is relevant in your case, but it seems
a likely candidate, since smtplib.py does not (and
should not) be looking up MX records for you, as far
as I know, while the "mail" utility might.

-Peter
Jul 19 '05 #8
Peter Hansen wrote:
dc******@gmail. com wrote:
OK, I've discovered the lost messages, but I'm still slightly confused
as to why they ended up there. The messages were being delivered to
the local machine, box1.domain.com , even though I was addressing them
to <user>@domain.c om.


The address is irrelevant with SMTP. What matters is


Well, that statement by itself is pretty silly... :-(

I hope you got my point from the rest of the post.

-Peter
Jul 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
10950
by: Bill | last post by:
I am trying to have the capability to email attachments. Specifically I want to be able to email a specific attachment that I name that may be a PDF document, text doc, etc. I already have a working piece of code that emails jpg attachments but does not work with any other types of attachments. Could someone tell me how to modify this code to...
2
4850
by: Garry Hodgson | last post by:
how do i use smtplib to send mail to someone with "cc" to someone else? if i just include the "to" addressees in the call to smtplib.sendmail(), and put the others in the "Cc" header fields, only the "To" recipients get the mail, thought the mail headers look right. but if i also add the "Cc" folks to the list of recipients in the call to...
1
2104
by: Hank | last post by:
Hi, I have a function that sends mail but I'm finding the number of characters in the To: field is limited to ~255 characters. This means that email is sent to only part of the email list. #recipients is a list of email addresses, greater than 255 characters in total
3
1829
by: mark.greenbank | last post by:
Hi, I'm writing a small script that generates email and I've noticed that: 1) one should add the 'To' and 'CC' headers to the email message 2) one needs to specify the recipients in the smtplib sendmail() method Can someone explain how these are related? Thanks,
6
9991
by: Matthias Kluwe | last post by:
Hi! After getting a @gmail.com address, I recognized I had to use TLS in my python scripts using smtplib in order to get mail to the smtp.gmail.com server. Things work well so far, apart from an unexpected error. Here's my sample code: import smtplib
12
2802
by: Chris Dewin | last post by:
Hi. I've been thinking about using smtplib to run a mailing list from my website. s = smtplib.SMTP("server") s.sendmail(fromaddress, toaddresess, msg) I know that in this instance, the toaddresses variable can be a variable of type list. Suppose the list contains well over 100 emails. Would that create some sort of drain on the mail...
7
2350
by: 3KWA | last post by:
Hi all, I tried to send a small mailing list using python today (2036 emails). For that purpose I looked in the doc for some code examples (I had never done it before). And I ended up writing and running this little script: # list.txt is a text file container an email per line fp=open('list.txt','r') list=fp.readlines()
2
6127
by: carlistixx | last post by:
Hi, I'm using the roundup issue tracker (http://roundup.sourceforge.net) which uses smtplib to send mail. It all worked until we moved to a hosted Exchange MTA. The hosting provider requires the use of TLS. Now roundup can't send mail. My version of python is: Python 2.3.4 (#1, Feb 6 2006, 10:38:46) on linux2
1
2382
by: Hunter | last post by:
I am writing a script that needs to send some emails. And I've used smtplib in the past and it is pretty easy. But I thought, gee it would be easier if I could just call it as a function, passing the from, to, subject, and message text. So I wrote it up as a function and it sort of works, but I get a weird error. When it runs it inserts a...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.