473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

SMTP Sending Mail Problem

Hi all,
I'm fairly new to python, but very excited about it's potential.

I'm trying to write a simple program that will accept input from a
command line and send email. The parameters I used on the command
line are for From address, To addresses, Subject and Body. For the
body, I thought it would be better to read the input from a file so I
could allow someone to nicely format the body with newlines in a text
editor and just read it into a string and send it.

However, whenever I try to read more than one line from the file, the
email is not being delivered. The only reason I know this is because
I tried just reading in the first line of the text file, and the email
sent fine. Right now I believe this must have something to do with
new line characters at the end of each line, but it doesn't quite make
sense to me why this is a problem, as I have also used the same script
and just created a string in it with multiple lines (\r\n) and sent it
and the email sends fine. To complicate the issue further, I have
turned used the set_debuglevel method so I can see the output from the
SMTP server, and it appears that the message was Queued for mail
delivery.

The SMTP server we are using is Exchange if that matters. I have
listed the code below, along with output from the SMTP server. Any
help would be much appreciated. (Note, I don't typically read in the
file with a range(n) iterator, but that is how I have noticed that I
can send only one line, but not send multiple lines. As soon as I
change the range value to 1, the email will successfully send the
first line of the text file).

import sys,smtplib
if len(sys.argv) != 5:
print """
Usage: sendmail FROM RECIPIENTS SUBJECT BODY
RECIPIENTS should be a semicolon delimited list of email addresses.
BODY should be a file where the message to send is stored
Use double quotes to surround the SUBJECT element if it is more than
one word
"""
exit()
fromaddr = sys.argv[1]
toaddrs = sys.argv[2].split(";")
subject = sys.argv[3]
body = ""
print toaddrs
print type(toaddrs)
try:
infile = open(sys.argv[4], 'r')
for i in range(4):
body = body + infile.readline()
except IOError:
print "Can't open the given file, please try again"
exit()
headers = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (fromaddr, ",
".join(toaddrs), subject)
msg = headers + body
server = smtplib.SMTP('##############')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

Output:

send: 'ehlo hplaptopr.############.com\r\n'
reply: '250-################.com Hello [10.#.#.#]\r\n'
reply: '250-SIZE 20971520\r\n'
reply: '250-DSN\r\n'
reply: '250-VRFY\r\n'
reply: '250-AUTH GSSAPI NTLM LOGIN\r\n'
reply: '250-AUTH=LOGIN\r\n'
reply: '250 OK\r\n'
reply: retcode (250); Msg: ################.com Hello [10.#.#.#]
SIZE 20971520
DSN
VRFY
AUTH GSSAPI NTLM LOGIN
AUTH=LOGIN
OK
send: 'mail FROM:<######@######.comsize=116\r\n'
reply: '250 2.1.0 #######@######.com....Sender OK\r\n'
reply: retcode (250); Msg: 2.1.0 ######@######.com....Sender OK
send: 'rcpt TO:<######@######.com>\r\n'
reply: '250 2.1.5 ######@######.com \r\n'
reply: retcode (250); Msg: 2.1.5 #######@######.com
send: 'data\r\n'
reply: '354 Start mail input; end with <CRLF>.<CRLF>\r\n'
reply: retcode (354); Msg: Start mail input; end with <CRLF>.<CRLF>
data: (354, 'Start mail input; end with <CRLF>.<CRLF>')
send: 'From: #######@######.com\r\nTo: ######@######.com\r\nSubject:
Test1\r\n\
r\nThis is from the file\r\nThis concludes our test\r\n\r\n\r\n.\r\n'
reply: '250 2.6.0 <############@###############.comQu
eued mail for delivery\r\n'
reply: retcode (250); Msg: 2.6.0 <##########@n#########.comQueued
mail for delivery
data: (250, '2.6.0 <########@################.comQ
ueued mail for delivery')
send: 'quit\r\n'
reply: '221 2.0.0 ################.com Service closing transmission
cha
nnel\r\n'
reply: retcode (221); Msg: 2.0.0 #################.com Service closing
t
ransmission channel
Jan 28 '08 #1
1 2851

I added a longer text file with vocabulary typically used in our
office and the email sent successfully. The crazy thing is I had
already checked all the spam filters and queues in Exchange, and the
older messages seem to have disappeared.

Sorry for the post, I thought I was going crazy for a bit! Thanks
again for the sanity check.
Jan 28 '08 #2

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

Similar topics

3
by: dale zhang | last post by:
Hi, I write an asp.net web application. It has a “Contact Us” page, where users fill in their email, subject and text and hit send. Then the email will go to my hard coded yahoo email...
4
by: z f | last post by:
Hi, i'm sending mail from the aspx page on the server. it is running on hosting, so i configure the System.Web.Mail.SmtpMail.SmtpServer property to my mail server. but problem is that sender...
11
by: JD | last post by:
Is it possible using the smtp class in asp.net to send emails and authenticate to the mail server that is sending the emails out. Currently I have a web application that works fine on my machine,...
34
by: antonyliu2002 | last post by:
I've set up the virtual smtp server on my IIS 5.1 like so: 1. Assign IP address to "All Unassigned", and listen to port 25. 2. Access Connection granted to "127.0.0.1". 3. Relay only allow...
2
by: oliu321 | last post by:
Hi, First I am not trying to write a client to talk with hotmail straightly. I am trying to write some codes to send emails through a SMTP server. I wrote a C++ version using pure socket...
11
by: ibiza | last post by:
Hi all, I am trying to use the System.Net.Mail class for the first time, with ASP.NET 2.0. I setup everything according to http://www.codeproject.com/aspnet/EasySMTP_package.asp, which gives...
4
by: =?Utf-8?B?dHBhcmtzNjk=?= | last post by:
I have a web page that at the click of a button must send a bunch (1000+) emails. Each email is sent individually. I have the code working fine, using Mail Message classes and smtp and all that. ...
7
by: oopsbabies | last post by:
Hello everyone, I am using Apache 1.3.33 as the web server and PHP version 4.3.10. My machine is using Windows XP 2002 professional edition which comes with a Windows firewall. I am using McAfee...
2
by: =?Utf-8?B?QWRl?= | last post by:
HI All, I am encountering the following error when I try to send an email through a SMTP server. I believe the problem lies with the authentication part when the network crednetials are used,...
9
by: SREEDEV | last post by:
I am sending a email with a HTML body from my VB.NET application using SMTP protocol. I am facing a problem when i send a long HTML text as body. Its working perfectly with small HTML body. But that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.