Python Forum
Email - Send email using Windows Live Mail - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Email - Send email using Windows Live Mail (/thread-2824.html)



Email - Send email using Windows Live Mail - cyberzen - Apr-13-2017

Hi all, 

As above matters, i have some problem how to send email using my default email client (Windows live mail) using Python.

After some exploring, i have found that we can use webbrowser.open or use the win32.client.

I have success to open the compose message but when i try to put attach file, its not appear in the new message box.

Please help. Below is my code.

Thanks



import webbrowser

recipient = '[email protected]'
subject = 'test'
body = 'This is testing message'
attach = r'c:\\Temp\\hhtlatest.txt'

webbrowser.open('mailto:?to='+ recipient + '&subject=' + subject +'&body=' + body + '&attachment=' + attach, new=1)



RE: Email - Send email using Windows Live Mail - snippsat - Apr-13-2017

The more standard approach is to use smtplib.
Eg:
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText

fromaddr = 'Your adress'
toaddr = 'Adress you want to send to'
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = 'Subject of the mail'

body = 'Your message here'
msg.attach(MIMEText(body, 'plain'))

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('User_name', 'password')
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
Output:
Common smtp servers Name Server Authentication Port Gmail smtp.gmail.com SSL 465 Gmail smtp.gmail.com StartTLS 587 Hotmail smtp.live.com SSL 465 Mail.com smtp.mail.com SSL 465 Outlook.com smtp.live.com StartTLS 587 Office365.com smtp.office365.com StartTLS 587 Yahoo Mail smtp.mail.yahoo.com SSL 465
# TLS
server = smtplib.SMTP("smtp.mail.yahoo.com", 587)

# SSL
server = smtplib.SMTP_SSL('smtp.mail.yahoo.com', 465)



RE: Email - Send email using Windows Live Mail - cyberzen - Apr-13-2017

Thanks for the reply.

It's going fine and good to use smtplib. But in my enviroment, i need to create program that to be use with 30 different users and they have each own email address.

I try to find  solution that, the program will use default email client in their PC to send the data using python. I just find out the information about Outlook only.

Not for others application such as Windows Live Mail.

Please help.

Thanks you Smile