smtplib

send email to localhost from localhost via python

筅森魡賤 提交于 2020-01-05 15:16:56
问题 I'm building and testing a web service on my local machine before i put it in production. I want to test the mail service. I'm using the standard python email and smtplib libraries. import smtplib from email.mime.text import MIMEText fp = open('textfile', 'rb') msg = MIMEText(fp.read()) fp.close() me = 'me_email@localhost' you = 'me_again_email@localhost' msg['Subject'] = 'The contents of %s' %fp msg['From'] = me msg['To'] = you s = smtplib.SMTP('localhost') s.sendmail(me, [you], msg.as

Is it possible to save the sent email into the sent items folder using python?

为君一笑 提交于 2020-01-05 07:54:14
问题 I want to sends an email but sent mail is empty. how to send an email, and then put a copy of it in the "Sent" mail folder. what can i do? 回答1: Yes, its possible. Basicaly you need to create an MIME email and then send it throug smptlib and than save it on Sent with imaplib. The official imaplib documentation. More detailed examples of using imaplib. Here is an example: import time import ssl import imaplib import smtplib import email from email import encoders from email.mime.base import

WinError 10060 A connection attempt failed because the connected party did not properly respond

血红的双手。 提交于 2020-01-01 19:39:47
问题 I am trying to verify emails by sending requests to SMTP servers. When I test in Linux, it works for 90% of emails. When I test in Windows, I did some analysis and like for 79% of emails will show the WinError10060 problem. I tried using VPN, proxies and even turning off the firewall but the same problem will appear: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host

New to Python, GMail SMTP error

北慕城南 提交于 2020-01-01 07:47:48
问题 I am writing a simple sendmail function to myself and I keep getting this error: NameError: name 'SMTPException' is not defined What is wrong with my code? Any suggestions? import smtplib sender = "user@gmail.com" receiver = ["user@gmail.com"] message = "Hello!" try: session = smptlib.SMTP('smtp.gmail.com',587) session.ehlo() session.starttls() session.ehlo() session.login(sender,'password') session.sendmail(sender,receiver,message) session.quit() except SMTPException: print('Error') 回答1: In

New to Python, GMail SMTP error

北城以北 提交于 2020-01-01 07:47:32
问题 I am writing a simple sendmail function to myself and I keep getting this error: NameError: name 'SMTPException' is not defined What is wrong with my code? Any suggestions? import smtplib sender = "user@gmail.com" receiver = ["user@gmail.com"] message = "Hello!" try: session = smptlib.SMTP('smtp.gmail.com',587) session.ehlo() session.starttls() session.ehlo() session.login(sender,'password') session.sendmail(sender,receiver,message) session.quit() except SMTPException: print('Error') 回答1: In

add sender's name in the from field of the email in python

[亡魂溺海] 提交于 2020-01-01 03:10:11
问题 I am trying to send email with below code. import smtplib from email.mime.text import MIMEText sender = 'sender@sender.com' def mail_me(cont, receiver): msg = MIMEText(cont, 'html') recipients = ",".join(receiver) msg['Subject'] = 'Test-email' msg['From'] = "XYZ ABC" msg['To'] = recipients # Send the message via our own SMTP server. try: s = smtplib.SMTP('localhost') s.sendmail(sender, receiver, msg.as_string()) print "Successfully sent email" except SMTPException: print "Error: unable to

Python TimeoutError: [WinError 10060] A connection attempt failed

*爱你&永不变心* 提交于 2020-01-01 00:52:14
问题 I am trying to make a python program that checks to see if the cost has changed or not for a website. However, every time I run the code it comes up with this python error below and then I can not access the site on any devices in the house for a period of time without is saying 'This site can’t be reached the site took too long to respond.' Even though it doesn't load for me the website is still working Code below try: from urllib.request import urlopen import smtplib import time except

python & smtplib: Is sending mail via gmail using oauth2 possible?

送分小仙女□ 提交于 2019-12-31 10:52:09
问题 So I can login to and send mail through gmail using smtplib (using the script below), but I was just wondering if using oauth2 was an option like with imaplib? I didn't see anything on the smtplib documentation page about oauth and I haven't found anything googling. Thanks. #! /usr/bin/python import smtplib to = 'myemailaddress' gmail_user = 'myemailaddress' gmail_pwd = 'passwd' smtpserver = smtplib.SMTP("smtp.gmail.com",587) smtpserver.ehlo() smtpserver.starttls() smtpserver.ehlo smtpserver

python & smtplib: Is sending mail via gmail using oauth2 possible?

只愿长相守 提交于 2019-12-31 10:51:37
问题 So I can login to and send mail through gmail using smtplib (using the script below), but I was just wondering if using oauth2 was an option like with imaplib? I didn't see anything on the smtplib documentation page about oauth and I haven't found anything googling. Thanks. #! /usr/bin/python import smtplib to = 'myemailaddress' gmail_user = 'myemailaddress' gmail_pwd = 'passwd' smtpserver = smtplib.SMTP("smtp.gmail.com",587) smtpserver.ehlo() smtpserver.starttls() smtpserver.ehlo smtpserver

Issue with sending mails from a distribution mail id [Python]

爷,独闯天下 提交于 2019-12-30 11:15:04
问题 I have seen the following question but I still have a few doubts. Sending an email from a distribution list Firstly I have an individual mail account as well as a distribution id used for a group in a particular mail server. I am able to send mails from the distribution mail id through outlook just by specifying the From field. It requires no authentication. I have been using the following code to send mails through my personal account: import smtplib from email.mime.multipart import