473,657 Members | 2,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending e-mail

I work at a training center and I would like to use Python to generate
a number of certificates and then e-mail them. The certificates are a
problem for another day - right now I just want to figure out how to
send an e-mail.

I confess I don't know much about the protocol(s) for e-mail. In PHP
using CodeIgniter, the same task was amazingly easy. I think this is a
bit harder because I'm not executing code on a remote machine that has
its own SMTP server. According to (http://www.devshed.com/c/a/Python/
Python-Email-Libraries-SMTP-and-Email-Parsing/), I need to use the
SMTP object found in the smtplib module to initiate a connection to a
server before I can send. I want to use Gmail, but on the following
input it stalls and then raises smtplib.SMTPSer verDisconnected :

server = SMTP("smtp.gmai l.com")

I also pinged smtp.gmail.com and tried it with the dotted quad IP as a
string. Am I on the right track? Is this a problem with gmail, or have
I gotten an assumption wrong?

Here's a thought: Could I use SMTPServer (http://docs.python.org/lib/
node620.html) to obviate the need to have anything to do with Gmail?
What would be the limitations on that? Could I successfully do this
and wrap the whole thing up in a black box? What modules would I need?

Thanks.
Aug 28 '08 #1
4 1458
On Aug 28, 12:52*pm, peter.jones.... @gmail.com wrote:
I work at a training center and I would like to use Python to generate
a number of certificates and then e-mail them. The certificates are a
problem for another day - right now I just want to figure out how to
send an e-mail.

I confess I don't know much about the protocol(s) for e-mail. In PHP
using CodeIgniter, the same task was amazingly easy. I think this is a
bit harder because I'm not executing code on a remote machine that has
its own SMTP server. According to (http://www.devshed.com/c/a/Python/
Python-Email-Libraries-SMTP-and-Email-Parsing/), I need to use the
SMTP object found in the smtplib module to initiate a connection to a
server before I can send. I want to use Gmail, but on the following
input it stalls and then raises smtplib.SMTPSer verDisconnected :

server = SMTP("smtp.gmai l.com")

I also pinged smtp.gmail.com and tried it with the dotted quad IP as a
string. Am I on the right track? Is this a problem with gmail, or have
I gotten an assumption wrong?

Here's a thought: Could I use SMTPServer (http://docs.python.org/lib/
node620.html) to obviate the need to have anything to do with Gmail?
What would be the limitations on that? Could I successfully do this
and wrap the whole thing up in a black box? What modules would I need?

Thanks.
Gmail SMTP server needs authentication.
I little googling found this example.
I did not test it if it works but it could be starting point.

http://codecomments.wordpress.com/20...-smtp-example/
Aug 28 '08 #2
Peter here is an example. I just tried it and it works fine.

from smtplib import SMTP
HOST = "smtp.gmail.com "
PORT = 587
ACCOUNT = "" # put your gmail email account name here
PASSWORD = "" # put your gmail email account password here

def send_email(to_a ddrs, subject, msg):
server = SMTP(HOST,PORT)
server.set_debu glevel(1) # you don't need this
server.ehlo()
server.starttls ()
server.ehlo()
server.login(AC COUNT, PASSWORD)
server.sendmail (ACCOUNT, to_addrs,
"""From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s\r\ n.\r\n""" % (
ACCOUNT, ",".join(to_add rs), subject, msg
)
)
server.quit()

if __name__ == "__main__":
send_email( ['s******@somewh ere.com'], 'this is just a test',
"hello world!" )
Aug 28 '08 #3
On Aug 28, 3:23 pm, gordyt <gor...@gmail.c omwrote:
Peter here is an example. I just tried it and it works fine.

from smtplib import SMTP
HOST = "smtp.gmail.com "
PORT = 587
ACCOUNT = "" # put your gmail email account name here
PASSWORD = "" # put your gmail email account password here

def send_email(to_a ddrs, subject, msg):
server = SMTP(HOST,PORT)
server.set_debu glevel(1) # you don't need this
server.ehlo()
server.starttls ()
server.ehlo()
server.login(AC COUNT, PASSWORD)
server.sendmail (ACCOUNT, to_addrs,
"""From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s\r\ n.\r\n""" % (
ACCOUNT, ",".join(to_add rs), subject, msg
)
)
server.quit()

if __name__ == "__main__":
send_email( ['some...@somewh ere.com'], 'this is just a test',
"hello world!" )
Thanks to everyone who's replied. gordyt, I didn't dare dream anyone
would hand me fully functional source code, so thank you very much for
that. Unfortunately, it doesn't work for me, likely because of some
complication from my company's firewall.

All things considered, going through Gmail is an unnecessary step if I
can run a server on my own PC. Is there any hope of this working? Can
it be done easily? Is there anything I should know about the
SMTPServer object, and are there any other modules I'd need?

Thanks again for all the help.
Aug 29 '08 #4
On Aug 29, 11:44*am, peter.jones.... @gmail.com wrote:
On Aug 28, 3:23 pm, gordyt <gor...@gmail.c omwrote:
Peter here is an example. *I just tried it and it works fine.
from smtplib import SMTP
HOST = "smtp.gmail.com "
PORT = 587
ACCOUNT = "" *# put your gmail email account name here
PASSWORD = "" *# put your gmail email account password here
def send_email(to_a ddrs, subject, msg):
* * server = SMTP(HOST,PORT)
* * server.set_debu glevel(1) * *# you don't need this
* * server.ehlo()
* * server.starttls ()
* * server.ehlo()
* * server.login(AC COUNT, PASSWORD)
* * server.sendmail (ACCOUNT, to_addrs,
* * * * """From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s\r\ n.\r\n""" % (
* * * * * * ACCOUNT, ",".join(to_add rs), subject, msg
* * * * )
* * )
* * server.quit()
if __name__ == "__main__":
* * send_email( ['some...@somewh ere.com'], 'this is just a test',
* * * * "hello world!" )

Thanks to everyone who's replied. gordyt, I didn't dare dream anyone
would hand me fully functional source code, so thank you very much for
that. Unfortunately, it doesn't work for me, likely because of some
complication from my company's firewall.

All things considered, going through Gmail is an unnecessary step if I
can run a server on my own PC. Is there any hope of this working? Can
it be done easily? Is there anything I should know about the
SMTPServer object, and are there any other modules I'd need?

Thanks again for all the help.
I would recommend looking at the email module too as it is a little
bit more flexible:

http://docs.python.org/lib/module-email.html

You could also see how I do it in wxPython: http://www.blog.pythonlibrary.org/?p=38

My script is Windows only at the moment.

Mike
Aug 29 '08 #5

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

Similar topics

3
7041
by: Paul Lamonby | last post by:
Hi, I am sending a file from the server as an email attachment. The file is being attached no problem and sending the email, but I get an error when I try to open it saying it is corrupt. Obviuosly, the file is fine on the server, so the attachment code I am using must be corrupting it, but I dont know what it is: // send email with attachment function emailAttachment($to, $subject, $message, $name, $email,
1
14517
by: coder_1024 | last post by:
I'm trying to send a packet of binary data to a UDP server. If I send a text string, it works fine. If I attempt to send binary data, it sends a UDP packet with 0 bytes of data (just the headers). I can see this because I'm running Ethereal and watching the packets. I'm defining the packets as shown below: $text_msg = "Hello, world\r\n"; $binary_msg = chr(0x01).chr(0x02).chr(0x03).chr(0x00).chr(0xA0); $binary_msg_size = 5;
3
4626
by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, I use the System.Net.Sockets to send/receive data (no tcpclient/tcplistener), I made a receivethread in my wrapper, the receivethread loops/sleeps while waiting for data and then fires a datareceived event. Within the waitingloop there is a timeout function, but I want the the 'last-time-socket-used' variable set when the socket is finished sending. When I send by System.Net.Sockets.Socket.Send(buffer()) (<--this...
4
8197
by: yaron | last post by:
Hi, I have a problem when sending data over TCP socket from c# client to java server. the connection established ok, but i can't send data from c# client to java server. it's work ok with TcpClient, NetworkStream and StreamWriter classes. but with low level socket it doesn't work (When using the Socket class Send method).
3
7719
by: Sydney | last post by:
Hi, I am trying to construct a WSE 2.0 security SOAP request in VBScript on an HTML page to send off to a webservice. I think I've almost got it but I'm having an issue generating the nonce value for the UserName token. Is it possilbe at all to do this from VBScript (or jscript?)? I know I will be limited with what I can do with the SOAP message. Eg/ can't sign/encrypt it etc. Thanks,
3
11328
by: Sells, Fred | last post by:
I'm using MSW XP Pro with Python 2.4 to develop but production will be Linux with Python 2.3. (could upgrade to 2.4 if absolutely necessary) I can also switch to Linux for development if necessary. I am writing some python to replace proprietary software that talks to a timeclock via UDP. The timeclock extracts the sending port from the UDP header and uses that for all response messages.
9
4915
by: Miro | last post by:
VB 2003 at the end of the code, this works great. bytCommand = Encoding.ASCII.GetBytes("testing hello send text") udpClient.Send(bytCommand, bytCommand.Length) and this recieves it Dim strReturnData As String = _ System.Text.Encoding.ASCII.GetString(receiveBytes)
0
1855
by: remya1000 | last post by:
by using FTP i can send files to server using vb.net. if the file is big, then it will take some time to complete the sending process to server.or if we were sending 3-4 files to the server one by one,then whethere we can show the progress of each file sending to server in progress bar. so that the FTP clients can see the progress of file sending to the server. any idea how we can do this to show the progress of each file sending. if we...
10
5075
by: Markgoldin | last post by:
I am sending an XML data from not dontnet process to a .Net via socket listener. Here is a data sample: <VFPData> <serverdata> <coderun>updateFloor</coderun> <area>MD2</area> <zone>BOXING</zone> <status>Running</status> <job>1000139233</job>
0
8385
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8303
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8502
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
8602
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
7316
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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
4150
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...
1
2726
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
1601
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.