473,401 Members | 2,146 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,401 software developers and data experts.

How to send mails using python (SMTP)?

2
Hi,
I started learning python a month ago.My problem now is, I need to send a
mail to my gmail account using a python script.Can this be done? I did try
out a lot of python codes but none of them really worked. Please help me
out. Also kindly mention the names of some good python books for a beginner.
Feb 24 '08 #1
3 7993
Dive into Python should be a good book. http://www.diveintopython.org/
Apr 11 '08 #2
Hello!

I think this code is what you need.Adjust it to your needs.....
Sorry , but i dont remember where i got it from......

Expand|Select|Wrap|Line Numbers
  1.  
  2. import smtplib
  3.  
  4. smtpserver = 'foo.foo.foo'
  5. AUTHREQUIRED = 1 # if you need to use SMTP AUTH set to 1
  6. smtpuser = 'spam'  # for SMTP AUTH, set SMTP username here
  7. smtppass = 'egs'  # for SMTP AUTH, set SMTP password here
  8.  
  9. RECIPIENTS = ['arecipient@somewhere.com']
  10. SENDER = 'youremail@somewhere.com'
  11. mssg = "The Message"
  12.  
  13. session = smtplib.SMTP(smtpserver)
  14. if AUTHREQUIRED:
  15.     session.login(smtpuser, smtppass)
  16. smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)
  17.  
  18. if smtpresult:
  19.     errstr = ""
  20.     for recip in smtpresult.keys():
  21.         errstr = """Could not delivery mail to: %s
  22.         Server said: %s %s %s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)
  23.     raise smtplib.SMTPException, errstr
  24.  
Elias
Jun 12 '08 #3
jlm699
314 100+
You can try searching bytes.com for the phrase "Python SMTP" for older posts on this topic. Here's the most recent.

HTH
Jun 12 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

29
by: | last post by:
I did a working code with CDONTS on NT4 Now I am testing is on w2k and it looks like objCDONTS.Send is completely ignored. I think is it ignored because it throws no errors, neither does the...
3
by: Carlos Lozano | last post by:
Hi, I know I can create e-mails and send them using System.Web.Mail, but I was wondering how can I do it using the POP3 settings on Office Outlook or Outlook Express. The problem I have is some...
1
by: michi | last post by:
Hi there.... Got here a tricky thing with my SMTP. First I show you what works on my machine.. **This Works** SmtpMail.SmtpServer = "mail.gmx.net" <-gmx is my mail provider...
1
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...
0
by: jlconde | last post by:
I have a classe to send mails. It runs on yahoo well but with hotmail I never receive the mails.I do not receive an error neither. I would need some strange header to make the hotmail like my...
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...
5
by: Sin Jeong-hun | last post by:
Hi. I would like to let users send bug reports or other messages to me. Maybe the easiest way to send e-mails from my application is just use the default e-mail agent by executing a link...
3
by: BLUE | last post by:
I want to send an email from my web service. I do not want to act like an email client, giving credentials of an existing email account to send messages: I would like to send my mail directly to...
13
by: btreddy | last post by:
Hii all, I've been searching in the internet just to know abt SMTP server. Can anybody tell me how to configure the SMTP server and how can i send the mails and how could i check whether...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
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,...
0
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...

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.