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
#2
It should work.
I replaced to gmail because i don't have yahoo.
server = smtplib.SMTP('smtp.gmail.com', 587)
Then just copy in address and password,no change to code.
Send and it work.

Check that yahoo can revive from 3 party service like this.
Remember there where i option i had to turn on to get gmail receive from all sources(allow less secure apps).
Reply
#3
thank you snippsat

i worked for myself by my gmail account

but i,m still thinking about sending email from my yahoo account
Reply
#4
Try:
server = smtplib.SMTP("smtp.mail.yahoo.com", 587)
For port 465 i think you need to change to this.
server = smtplib.SMTP_SSL('smtp.mail.yahoo.com', 465)
This create a SSL connection right from the start.
The difference is method .SMTP_SSL() which is used with 465.
Reply
#5
thank you

it worked with your help:
server = smtplib.SMTP("smtp.mail.yahoo.com", 587)
Reply


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,527 May-07-2022, 10:32 AM
Last Post: stanislav
  Python Automated Email aidanh26 10 4,522 Jul-13-2020, 04:09 PM
Last Post: aidanh26
  Help send email by Python using smtplib hangme 6 6,184 Jan-25-2020, 03:31 AM
Last Post: shapeg
  Threading with python in sending multiple commands? searching1 0 3,992 Jun-12-2019, 09:13 PM
Last Post: searching1
  How to run local python script to remote machine without sending krishna1989 1 8,330 Feb-21-2019, 05:18 PM
Last Post: marienbad
  Sending DNS responses with python - research dnsman2018 0 4,949 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