473,888 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

smtp question

Hi,

I am testing the smtp module and have the following question:

in the code below (taken from net sample) prior to adding the "Subject:"
field, the email client found the "From" and the "To". Without the
"Subject:" field on I get this:

Email client = Evolution: the "From" field is blank
Email client = KMail: the "To" field is blank

Any clue ?

Thanks and regards,

Philippe
*************** *******

import smtplib

def prompt(prompt):
return raw_input(promp t).strip()
fromaddr = prompt("From: ")
toaddrs = prompt("To: ").split()
print "Enter message, end with ^D (Unix) or ^Z (Windows):"

# Add the From: and To: headers at the start!
msg = ("From: %s\r\nTo: %s\r\n\r\n" % (fromaddr, ", ".join(toaddrs) ))
while 1:
try:
line = raw_input()
except EOFError:
break
if not line:
break
msg = msg + line

print "Message length is " + repr(len(msg))

server = smtplib.SMTP('s mtp.sbcglobal.y ahoo.com')
server.set_debu glevel(1)
server.login ('xxxxx','yyyyy yy')
server.sendmail (fromaddr, toaddrs, 'Subject:from python\n\n'+msg )
server.quit()



--
*************** ************
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
*************** ************

Jul 18 '05 #1
4 1797
Philippe,

Looks like the problem lies where you have added the Subject header.
You have terminated it with a \n\n and then your From and To headers.
You may want to rewrite it as:

server.sendmail (fromaddr, toaddrs, 'Subject:from python\r\n'+msg )

Why dont you consider using the email module -
http://python.org/doc/2.4/lib/module-email.html ? It is elegant and
easy to use.

Thank you,
--Kartic

Jul 18 '05 #2
"Philippe C. Martin" <ph************ *@sbcglobal.net > writes:
Hi,

I am testing the smtp module and have the following question:

in the code below (taken from net sample) prior to adding the "Subject:"
field, the email client found the "From" and the "To". Without the
"Subject:" field on I get this:

Email client = Evolution: the "From" field is blank
Email client = KMail: the "To" field is blank

Any clue ?

Thanks and regards,

Philippe
*************** *******

import smtplib

def prompt(prompt):
return raw_input(promp t).strip()
fromaddr = prompt("From: ")
toaddrs = prompt("To: ").split()
print "Enter message, end with ^D (Unix) or ^Z (Windows):"

# Add the From: and To: headers at the start!
msg = ("From: %s\r\nTo: %s\r\n\r\n" % (fromaddr, ", ".join(toaddrs) ))
while 1:
try:
line = raw_input()
except EOFError:
break
if not line:
break
msg = msg + line

print "Message length is " + repr(len(msg))

server = smtplib.SMTP('s mtp.sbcglobal.y ahoo.com')
server.set_debu glevel(1)
server.login ('xxxxx','yyyyy yy')
server.sendmail (fromaddr, toaddrs, 'Subject:from python\n\n'+msg )


You've got \n\n after the Subject line, not \r\n. That is being treated
as two newlines, thus ending the headers.

<mike

--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 18 '05 #3
Philippe C. Martin wrote:
Hi,

I am testing the smtp module and have the following question:

in the code below (taken from net sample) prior to adding the "Subject:"
field, the email client found the "From" and the "To". Without the
"Subject:" field on I get this:

Email client = Evolution: the "From" field is blank
Email client = KMail: the "To" field is blank

Any clue ?


It' very easy to create email messages with the email module.
from email.Message import Message
fromaddr = 'm***@mxm.dk'
to = 'm***@mxm.dk'
msg = Message()
msg['Subject'] = 'From Python'
msg['From'] = fromaddr
msg['To'] = to
body = "This is the message content"
msg.set_payload (body)
Thats all. Though some smtp servers needs a Date header too, to work.
from time import gmtime, strftime
msg['Date'] = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
Sending the message via the smtp module is even simpler.
import smtplib
server = smtplib.SMTP('l ocalhost')
server.sendmail (fromaddr, [to], msg.as_string() )
server.quit()

--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
Jul 18 '05 #4
"Philippe C. Martin" <ph************ *@sbcglobal.net > wrote:
Hi,

I am testing the smtp module and have the following question:

in the code below (taken from net sample) prior to adding the "Subject:"
field, the email client found the "From" and the "To". Without the
"Subject:" field on I get this:

Email client = Evolution: the "From" field is blank
Email client = KMail: the "To" field is blank

Any clue ?
Absolutely.
server = smtplib.SMTP('s mtp.sbcglobal.y ahoo.com')
server.set_deb uglevel(1)
server.login ('xxxxx','yyyyy yy')
server.sendmai l(fromaddr, toaddrs, 'Subject:from python\n\n'+msg )
server.quit( )
You have two newlines following the Subject: line. That inserts a blank
line, which terminates the headers. Everything else, including the From:
and To: lines, will be taken as part of the message body. I assume you
meant to use \r\n, but \n will work just as well and is less error prone.
print "Message length is " + repr(len(msg))


Easier is:
print "Message length is", len(msg)
More efficient is:
print "Message length is %d" % len(msg)
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #5

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

Similar topics

1
9893
by: ehendrikd | last post by:
hi all i have written a php site that uses the mail() on windows and i had to state in the php.ini file which smtp server to use. have now migrated this site to a redhat 9 server, but i still want the emails to be sent via the smtp server i stated earlier. this may infact be a sendmail question, im not sure, (perhaps changing sendmail_path in php.ini) but has anyone managed to send email via
2
2818
by: Dan Boyle | last post by:
Hi, I am having difficulty connection to an smtp host. I am using the following code but I don't think I fully understand what smtp host can be used. function setSMTPParams($host = null, $port = null, $helo = null, $auth = null, $user = null, $pass = null) { if (!is_null($host)) $this->smtp_params = $host;
21
3396
by: Nancy | last post by:
Hi, Guys, Is there any other way to use python or mod_python writing a web page? I mean, not use "form.py/email", no SMTP server. <form action="form.py/email" method="POST"> ... Thanks a lot. Nancy W
5
2507
by: Charlie | last post by:
Hi: I'm working on an e-commerce site. Using the SMTP class, my site sends out confirmation messages. It works most of the time, but sometimes raises an error. I need a way of making sure it goes out every time. I thought about wrapping a try-catch handler in loop that keeps on retrying if delivery fails. Is this a good idea? If not, what is the best way of handling this kind of thing? Thanks,
3
3046
by: RN | last post by:
I am tired of sending mail from the built-in SMTP service for so many reasons (errors are nondescriptive in the event log, it doesn't let me control which IP address it sends from, and it identifies itself as the computer name which is not in domain.com format, triggering spam filter problems). Instead, I want to have my code send through an SMTP server of a company that we pay for mail service. But they require a username and password....
1
1539
by: Nigel | last post by:
I know there are lots of threads covering my question but i am still unable to send e-mails from an asp.net page. Messages are not even going into the logs. Here is the code that i am using to send the e-mail. MailMessage objMail = new MailMessage(); objMail.From = "nigel@***"; objMail.To = nigel@***; objMail.Subject = txtSubject.Text;
6
1530
by: Dushyant | last post by:
Hi everyone, I am working on an application, where I need to mail some xml files as attachments. I tried to use System.Diagnostic.Process class but it does not provide any help for attaching a file automatically. Then I resorted to System. Web namespace but here also it does not take the SMTP server's address automatically. I have to mention it. The application on which I am working is a general purpose application and user might not be...
5
1481
by: trevisc | last post by:
Good afternoon everyone. I'm currently trying to build an automated invoice system that collects dynamic data and automatically sends out invoices. In my test database I have 23 companies that i'm trying to send out. I am currently using Web.Mail.MailMessage with my cable internet SMTP as the server to send out to. I've noticed that if I just run it straight through it will time out (almost like the server detects it's being over...
6
5214
by: phpmagesh | last post by:
Hi, I am using mail function in my php page, As soon i update the details, i have to send mail to the customer with the updated details, problem is when i send mail it simple through waring msg as: can anyone help me why such problem occurs, how to over come this problem.
0
11182
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
10778
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
10886
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7990
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
5824
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
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4642
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
4245
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.