smtplib

How do I send attachments using SMTP?

蓝咒 提交于 2019-11-26 12:10:04
问题 I want to write a program that sends email using Python\'s smtplib. I searched through the document and the RFCs, but couldn\'t find anything related to attachments. Thus, I\'m sure there\'s some higher-level concept I\'m missing out on. Can someone clue me in on how attachments work in SMTP? 回答1: What you want to check out is the email module. It lets you build MIME-compliant messages that you then send with smtplib. 回答2: Here is an example of a message with a PDF attachment, a text "body"

smtplib sends blank message if the message contain certain characters

こ雲淡風輕ζ 提交于 2019-11-26 11:38:09
问题 My current script allows me to send emails fine, but there are just some characters it doesn\'t like, particularly \':\' in this sample. import smtplib, sys mensaje = sys.argv[1] def mailto(toaddrs, msg): fromaddr = \'myemailblabla\' username = \'thisismyemail\' password = \'122344\' server = smtplib.SMTP(\'smtp.gmail.com:587\') server.starttls() server.login(username, password) server.sendmail(fromaddr, toaddrs, msg) server.quit() mailto(\'test@gmail.com\', mensaje) If I write a sample

SMTPAuthenticationError when sending mail using gmail and python [duplicate]

柔情痞子 提交于 2019-11-26 07:25:10
问题 This question already has an answer here: How to send an email with Gmail as provider using Python? 13 answers when i try to send mail using gmail and python error occurred this type of question are already in this site but doesn\'t help to me gmail_user = \"me@gmail.com\" gmail_pwd = \"password\" TO = \'friend@gmail.com\' SUBJECT = \"Testing sending using gmail\" TEXT = \"Testing sending mail using gmail servers\" server = smtplib.SMTP(\'smtp.gmail.com\', 587) server.ehlo() server.starttls()

How to send an email with Python?

你说的曾经没有我的故事 提交于 2019-11-26 06:52:13
问题 This code works and sends me an email just fine: import smtplib #SERVER = \"localhost\" FROM = \'monty@python.com\' TO = [\"jon@mycompany.com\"] # must be a list SUBJECT = \"Hello!\" TEXT = \"This message was sent with Python\'s smtplib.\" # Prepare actual message message = \"\"\"\\ From: %s To: %s Subject: %s %s \"\"\" % (FROM, \", \".join(TO), SUBJECT, TEXT) # Send the mail server = smtplib.SMTP(\'myserver\') server.sendmail(FROM, TO, message) server.quit() However if I try to wrap it in a

How to send email to multiple recipients using python smtplib?

百般思念 提交于 2019-11-26 01:46:36
问题 After much searching I couldn\'t find out how to use smtplib.sendmail to send to multiple recipients. The problem was every time the mail would be sent the mail headers would appear to contain multiple addresses, but in fact only the first recipient would receive the email. The problem seems to be that the email.Message module expects something different than the smtplib.sendmail() function. In short, to send to multiple recipients you should set the header to be a string of comma delimited

How to send email to multiple recipients using python smtplib?

北慕城南 提交于 2019-11-25 20:21:36
After much searching I couldn't find out how to use smtplib.sendmail to send to multiple recipients. The problem was every time the mail would be sent the mail headers would appear to contain multiple addresses, but in fact only the first recipient would receive the email. The problem seems to be that the email.Message module expects something different than the smtplib.sendmail() function. In short, to send to multiple recipients you should set the header to be a string of comma delimited email addresses. The sendmail() parameter to_addrs however should be a list of email addresses. from