Python Forum
sending email with python
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sending email with python
#1
hi

i want to send an email from my python program

i had write this code for doing that:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
print("1")
server = smtplib.SMTP('smtp.mail.yahoo.com',465) #smtp,port number
print("2")
server.ehlo()
server.starttls()
server.ehlo()
server.login("[email protected]","my password")


 
fromaddr = "[email protected]"
toaddr = "[email protected]"
subject = "From Python"
 
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = subject
print("3") 
body = "Sent from Python"
msg.attach(MIMEText(body, 'plain'))
 
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
print('ok')
but it doesnt work.
can you help me.
myself think that my mistake is in line 5.
thank you
Reply


Messages In This Thread
sending email with python - by shahpy - Oct-02-2016, 08:44 PM
RE: sending email with python - by snippsat - Oct-02-2016, 09:23 PM
RE: sending email with python - by shahpy - Oct-03-2016, 04:05 PM
RE: sending email with python - by snippsat - Oct-03-2016, 04:46 PM
RE: sending email with python - by shahpy - Oct-03-2016, 10:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python + PHP. Sending data from "Moodle" (php) to python CGI-script and get it back stanislav 0 1,558 May-07-2022, 10:32 AM
Last Post: stanislav
  Python Automated Email aidanh26 10 4,659 Jul-13-2020, 04:09 PM
Last Post: aidanh26
  Help send email by Python using smtplib hangme 6 6,242 Jan-25-2020, 03:31 AM
Last Post: shapeg
  Threading with python in sending multiple commands? searching1 0 4,040 Jun-12-2019, 09:13 PM
Last Post: searching1
  How to run local python script to remote machine without sending krishna1989 1 8,376 Feb-21-2019, 05:18 PM
Last Post: marienbad
  Sending DNS responses with python - research dnsman2018 0 5,006 Aug-05-2018, 12:01 PM
Last Post: dnsman2018

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020