473,785 Members | 2,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_debu glevel(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=11 6\r\n'
reply: '250 2.1.0 #######@######. com....Sender OK\r\n'
reply: retcode (250); Msg: 2.1.0 ######@######.c om....Sender OK
send: 'rcpt TO:<######@#### ##.com>\r\n'
reply: '250 2.1.5 ######@######.c om \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: ######@######.c om\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## #######.comQueu ed
mail for delivery
data: (250, '2.6.0 <########@##### ###########.com Q
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 2877

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
5588
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 account. I was using optimum online service with smtp server as “mail.optonline.net”. I can receive email correctly. Now I switch to verizon DSL. I change my smtp server accordingly as
4
2595
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 email is also configurable and since the sender email is not from the SMTP server same host, it is not allows to send. i need to ba able to configure the SMTP Auth to be authenticated to different user from the sender email, but i didn't find...
11
2028
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, will send email to both my company email addresses and to non-company email addresses. However, as soon as I move the app into the production server it does not send email to non company email addresses. What I mean by company is our domain...
34
18271
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 "127.0.0.1". 4. Authentication: "Anonymous access" only. 5. Outbound connection listen to TCP 25. Besides,
2
3622
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 programming and SMTP protocol, a VB version using CDO and a C# version using System.Net.Mail. Now all of them works great with any email account but hotmail. So here is the C# code:
11
2725
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 me a working environment for sending mails. I am sure the code is correct, there are no errors and everything seems
4
7686
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. But sometimes even when I'm just sending one e-mail the web page takes a minutes or so to post. Can anyone tell me why it is so slow, or how to fix the problem? To address this I am thinking of just creating a queue table to write the emails...
7
7746
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 free edition for anti-virus. I use an ISP provider from my country and according to them I do not need to perform authentication while sending mails through their SMTP address. Thus I am using external SMTP server. I don't have IIS installed...
2
12175
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, error is thrown at the .send point. Error is: The following error occured Sending an email: System.ApplicationException: An error occurred sending an email To helen@HerMail.com From ade@MyMail.com Cc Subject A test with Finlistener #1. The body...
9
3649
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 same long HTML body mail is working perfectly from a XP server and IIS 5.0. If host the same application in IIS 6.0 and windows 2003 server, this problem popsup. Here is my mail setting section in the web.config <system.net> ...
0
9647
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10356
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10161
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7506
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5390
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4058
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
2
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2890
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.