smtplib

Python: Get Gmail server with smtplib never ends

十年热恋 提交于 2019-12-11 05:29:12
问题 I simply tried: >>> import smtplib >>> server = smtplib.SMTP('smtp.gmail.com:587') in my Python interpreter but the second statement never ends. Can someone help? 回答1: You might find that you need a login and password as a prerequisite to a successful login-in. Try something like this: import smtplib ServerConnect = False try: smtp_server = smtplib.SMTP('smtp.gmail.com','587') smtp_server.login('your_login', 'password') ServerConnect = True except SMTPHeloError as e: print "Server did not

Email goes to first recipient only smtp mail python

痞子三分冷 提交于 2019-12-10 16:40:46
问题 I know, There are hundreds of questions with the same query. Sorry about this. I tried almost each of them. But still did not get the solution. In fact, I copied some of the code from one of stackoverflow query and improved it as per my requirement. I'm writing a script to send error report using python for one of our server. My problem is Email is sending to first member of RECIPIENTS only. It needs to be send to the team of managers as well as to the admins at a time. RECIPIENTS = ["mail1

Email attachment received as 'noname'

做~自己de王妃 提交于 2019-12-10 14:49:16
问题 The following Python function results in the attachment being named "noname" when it should be "text_file.txt". As you can see I've tried a 2 different approaches with MIMEBase and MIMEApplication. I've also tried MIMEMultipart('alternative') to no avail. def send_email(from_addr, to_addr_list, subject, html_body,plain_text_body, login, password, smtpserver='smtp.gmail.com:587', cc_addr_list=None, attachment=None, from_name=None): message=MIMEMultipart() plain=MIMEText(plain_text_body,'plain'

Send a list to HTML Email

末鹿安然 提交于 2019-12-08 13:52:05
问题 I am currently working with a HTML email document. Now I want to present a list with information from my database. How do I present the list in a HTML email? I've tried following: import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText articles = ['hello', 2, 5, 'bye'] me = "email@gmail.com" you = "email@gmail.com" subject = 'something' msg = MIMEMultipart('alternative') msg['Subject'] = subject msg['From'] = me msg['To'] = you html = """\ {% for i

Send individual emails to multiple recipients

让人想犯罪 __ 提交于 2019-12-08 11:22:13
问题 I have put together a code to send emails to multiple recipients. However each recipient receives all mails instead of his own. Dataframe: email content mark@gmail.com Hi Mark, bla bla eve@gmail.com Hi Eve, bla bla john@gmail.com Hi, John bla bla for content in df['content']: for email in df['email']: message = MIMEMultipart() message['Subject'] = "Subject" message['From'] = 'my email' message['Reply-to'] = 'my email' message['To'] = '{}'.format(email) text = MIMEText(mail) message.attach

python's smtplib cannot connect to gmail, mail.ru or anything else

…衆ロ難τιáo~ 提交于 2019-12-08 08:15:03
问题 All lines starting from line all return an error Errno 10060 or an error Errno 10061: import smtplib server = smtplib.SMTP('smtp.gmail.com:465') mailServer = smtplib.SMTP("smtp.gmail.com", 587) mailServer = smtplib.SMTP("smtp.gmail.com", 465) mailServer = smtplib.SMTP("smtp.mail.ru", 25) mailServer = smtplib.SMTP("smtp.mail.ru", 2525) Could you help? I must be missing something trivial... Error messages in full: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:

python smtplib multipart email body not showing on iphone

不打扰是莪最后的温柔 提交于 2019-12-08 07:54:37
问题 I am trying to send an email with an image using smtplib in python. The email shows up fine on my desktop and on the iphone gmail app, but on the standard iphone mail app the body doesn't appear. Here is my code: def send_html_email(self, subject, html, to_email,from_email, password, from_name, image=None): msg = MIMEMultipart('alternative') msg['From'] = from_name msg['To'] = to_email msg['Subject'] = subject html_message = MIMEText(html, "html") msg.attach(html_message) if image: msgImage =

SMTPAuthenticationError 5.7.14 Please log\n5.7.14 in via your web browser

前提是你 提交于 2019-12-08 00:12:24
问题 I have been struggling in finding a solution that can be applied to my case, as I viewed and reviewed many questions related to this issue. I have a script which sends periodically reports to a list of recipients. Everything worked fine until today 4 am, when I checked my inbox and the reports didn't come. By debugging the code: import smtplib username="my.user.account@gmail.com" password="my.correct.password" server=smtplib.SMTP('smtp.gmail.com',587) server.ehlo() server.starttls() server

[转载]用Python处理邮件

此生再无相见时 提交于 2019-12-07 20:26:39
总体来说python处理邮件还是比较方便的,库提供了很多工具.下面我把心得写出来,给新手一个启迪,也请高手给些更好的方法. 先说接受邮件. poplib 方法. 1.poplib.POP3('这里填入你pop邮件服务器地址') 登陆服务器. 2.poplib.user('用户名 ') poplib.pass_('密码') 3.poplib.stat()方法返回一个元组:(邮件数,邮件尺寸) mailCount,size=poplib.stat() 这样mailCount就是邮件的数量,size,就是所有邮件的大小. 4.poplib.rert('邮件号码')方法返回一个元组:(状态信息,邮件,邮件尺寸) hdr,message,octet=server.retr(1) 读去第一个邮件信息. hdr的内容就是响应信息和邮件大小比如'+OK 12498 octets' message 是包含邮件所有行的列表. octet 是这个邮件的内容. 得到的message是邮件的原始内容,也就是没有解码过的,里面的内容和标题基本上都是base64编码的,下面说说如何处理原始邮件. python 的email库里提供了很多处理邮件的方法,我们先把原始邮件转成email实例,这样就可以用库方法处理邮件. email.message_from_string()

smtplib.SMTP starttls fails with tlsv1 alert decode error

核能气质少年 提交于 2019-12-07 05:21:44
问题 I encountered the following perculiar behaviour today. The following code works on Python 3.3: smtp = smtplib.SMTP() smtp.connect(host="smtp.gmail.com", port=587) smtp.ehlo() smtp.starttls() In Pyhton 3.4 the above code doesn't work, instead the following error is encountered: File "smtp_test.py", line 10, in <module> smtp.starttls() File "/usr/lib/python3.4/smtplib.py", line 676, in starttls server_hostname=server_hostname) File "/usr/lib/python3.4/ssl.py", line 344, in wrap_socket _context