473,804 Members | 3,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Email Directly from python

I'd like to send email directly from within python without having to
rely on an external smtp server. You know, something like the good, old
Unix...

echo My_message | mail -s Subject pe****@someplac e.com

Can Python do something similar in a portable fashion without a smtp
server installed on the machine?

Thanks,
Brad
Feb 13 '08 #1
9 1595
brad wrote:
I'd like to send email directly from within python without having to
rely on an external smtp server. You know, something like the good, old
Unix...

echo My_message | mail -s Subject pe****@someplac e.com

Can Python do something similar in a portable fashion without a smtp
server installed on the machine?

Thanks,
Brad
smtp module can do what you want yes.

-Larry
Feb 13 '08 #2
Larry Bates wrote:
brad wrote:
>I'd like to send email directly from within python without having to
rely on an external smtp server. You know, something like the good,
old Unix...

echo My_message | mail -s Subject pe****@someplac e.com

Can Python do something similar in a portable fashion without a smtp
server installed on the machine?

Thanks,
Brad

smtp module can do what you want yes.

-Larry
The tricky part is how to resolve the mail server for a mail address.
Usually you have to query the mx record of that domain. I solved that by
looking if I can find the nslookup binary.

I already wrote a command line mailer that can do attachments too, no
need to write it again. If anybody is interested I can open-source it.

--
mph
Feb 13 '08 #3
2008/2/13, brad <by*******@gmai l.com>:
I'd like to send email directly from within python without having to
rely on an external smtp server. You know, something like the good, old
Unix...

echo My_message | mail -s Subject pe****@someplac e.com
I hope to not disappoint you, but mail will invoke a smtp server to
send your mail.
>
Can Python do something similar in a portable fashion without a smtp
server installed on the machine?
You can use a smtp server that is installed somewhere else.
>
Thanks,
Brad

--
http://mail.python.org/mailman/listinfo/python-list

--
-- Guilherme H. Polo Goncalves
Feb 13 '08 #4
Martin P. Hellwig wrote:
The tricky part is how to resolve the mail server for a mail address.
Usually you have to query the mx record of that domain. I solved that by
looking if I can find the nslookup binary.
The from and to are static constants... they don't change. Mail just
seems so tricky these days what with all the blacklists, greylists,
whitelists, etc. It's almost as if email is broken. Location of the
sending pc matters too. Just wondering if there is a super simple one
liner in Python (that's portable) that can do this.

Feb 13 '08 #5
brad wrote:
Martin P. Hellwig wrote:
>The tricky part is how to resolve the mail server for a mail address.
Usually you have to query the mx record of that domain. I solved that
by looking if I can find the nslookup binary.

The from and to are static constants... they don't change. Mail just
seems so tricky these days what with all the blacklists, greylists,
whitelists, etc. It's almost as if email is broken. Location of the
sending pc matters too. Just wondering if there is a super simple one
liner in Python (that's portable) that can do this.
Well the problem is that you can't control whether the to address won't
be handled with a different mail server in the future. Whether the
receiving party marks your mail as spam or not is actually their
problem. If you act according to the RFC's it should be delivered.
Of course it helps if you don't make the content be spam ;-)

--
mph
Feb 13 '08 #6
Martin P. Hellwig wrote:
<cut>
I already wrote a command line mailer that can do attachments too, no
need to write it again. If anybody is interested I can open-source it.
To reply on my own post ;-)
Even if nobody is interested in case you change your mind it is hosted
at: http://code.google.com/p/curtusmail/

Under the new BSD license, even included a stand-alone (py2exe) windows
version for the couple of remaining servers that have no python installed.

The non-compiled version should work on all platforms having a
reasonable new python version and nslookup.

--
mph
Feb 13 '08 #7
Guilherme Polo wrote:
<cut>
I hope to not disappoint you, but mail will invoke a smtp server to
send your mail.
<cut>
I disagree. If you really want to, all you need is telnet. You connect
to port 25 of the mail server that handles the mail of the domain for
that mail address and do the helo, mail from, rcpt to, data stuff.

Mail indeed does invoke a smtp server, but strictly speaking only to
receive it for the user.

--
mph

Feb 14 '08 #8
Dennis Lee Bieber wrote:
<cut>
The first response to the query was to invoke the command line
"mail" utility of a Unix type OS. THAT program is, what I believe, was
meant by "mail will invoke a smtp server"... Not "mail" as a general
concept, but the utility command...
Ah yes I see that now, sorry for the misinterpretati on.

--
mph
Feb 14 '08 #9
You could always just set up a gmail account and use that SMTP. Thats
what I do. Then all you have to do is google search for "gmail smtp
python" and get some easy code.

You can even send attatchments really easy.

-Daniel Folkes

brad wrote:
I'd like to send email directly from within python without having to
rely on an external smtp server. You know, something like the good, old
Unix...

echo My_message | mail -s Subject pe****@someplac e.com

Can Python do something similar in a portable fashion without a smtp
server installed on the machine?

Thanks,
Brad
Feb 15 '08 #10

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

Similar topics

10
2029
by: sean | last post by:
Is there a good module for sending out email? For a website that I am working on, I am writing a program that finds out which presenters have not yet confirmed their scheduled date and sends them an email to confirm. Does python have any modules for use with mail programs like sendmail, or should I just run everything with os.system and os.popen? Thanks for any help.
1
1733
by: Chuck Amadi | last post by:
A little help has anyone used the email-dir.py Email Module ,I have downloaded the example and would like some pointers to get it going . For example Have I got to add any parameters to python script or Do I just use the command line. Cheers
4
3735
by: Paul Schmidt | last post by:
Dear list: I am new to python, and I am trying to figure out the short answer on something. I want to open a POP3 mailbox, read the enclosed mail using the POP3 module, , and then process it using the email module. Environment Python 2.3.4, Mandrake Linux 9.0 patched up the wazoo...
0
1416
by: HIL | last post by:
Hi everybody, I wrote a python script to setup my network interface under Linux. To perform it, I use directly from my python script external programs as 'ifconfig' and 'route' ans I fill the file /etc/resolv.conf with the good nameserver IP. So, it it works and my network is up. My problem is that when I use the function socket.gethostbyaddr just after setting up the network and without getting out of my script, I get an exception...
0
1216
by: contentsecurity | last post by:
Your email message To : >From : python-list@python.org Subject : Server Report has been quarantined because it contains one or all of the following: 1. Infected with a worm/script based virus 2. Has a .zip, .exe, .com, .ink, .bat, .scr or .pif extension.
3
2522
by: Erik Johnson | last post by:
THE GOAL: I need to send an email with a simple ASCII text body and an attached HTML file. I have scripts that send basic emails via the smtplib module that don't have any attachements and that seems to work fine. I first looked at the mimetools modules but it says it is depreceated since 2.3, so I started trying to use the email module. Here is a script that basically follows the second example given in section 7.1.13 of the Python...
4
4812
by: Sallu | last post by:
Hi All, import re msg=raw_input('Enter the email : ') def validateEmail(email): #if re.match("^.+\\@(\\+\\.({2,3}| {1,3})(\\]?)$", email) != None: if re.match("^(+)@((?:+\.)+{2,})$", email) != None: print 'Valis'
0
167
by: Maric Michaud | last post by:
Le Monday 18 August 2008 12:43:02 Gabriel Genellina, vous avez écrit : escribió: Three options here : - dealing directly with outlook mailboxes files, I used some open source code to parse .pst files in past, but you'll need some googling to match your requirements. Doesn't help if there is an instance of outlook running on the box.
0
2151
by: Ahmed, Shakir | last post by:
Thanks everyone who tried to help me to parse incoming email from an exchange server: Now, I am getting following error; I am not sure where I am doing wrong. I appreciate any help how to resolve this error and extract emails from an exchange server. First I tried: Traceback (most recent call last): File "<interactive input>", line 1, in ? File "C:\Python24\lib\poplib.py", line 96, in __init__ raise socket.error, msg
0
10571
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
10326
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
10317
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
10075
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...
0
6851
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
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
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
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
3
2990
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.