最近我正在研究用于python的smtplib smtp客户端库,但我找不到任何对支持它的smtp服务器的PIPELINING协议的引用.有什么我想念的吗?它还没有实现?启用PIPELINING的任何其他实现而不是smtplib?
谢谢
我如何更改可执行二进制文件的真实文件扩展名以通过 gmail smtp 协议(全部在 python 中)发送该文件。
示例:“binary”到“binary.jpg”
我会试试这个:
导入 gzip,shutil
src = 打开('3c7983cb70e9630cc4ee2fe3e1fb16c2','rb')
dest = gzip.open('3c7983cb70e9630cc4ee2fe3e1fb16c2.gz.jpg', 'wb')
Shutil.copyfileobj(src, dest)
但是当我尝试通过 gmail smtp 发送时,发生了这种情况:
smtplib.SMTPDataError: (552, '5.7.0 我们的系统在您的邮件中检测到非法附件。请\n5.7.0 访问 http://mail.google.com/support/bin/answer.py?answer=6590 以\ n5.7.0 查看我们的附件指南。n18sm433437wbh.23')
提前致谢。
我正在尝试编写一个使用 Python 库发送电子邮件的 Python 类smtplib。我让它可以与标准 Gmail 一起使用,但在让配置与其他帐户一起使用时遇到问题。
Emailer类配置和发送方法:
def configure(self, serverLogin, serverPassword, fromAddr, toAddr, serverHost='mail.myserver.edu', serverPort=465):
self.server=smtplib.SMTP(serverHost,serverPort) #set the server host/port - currently configured for gmail
self.server.ehlo()
self.server.starttls()
self.server.ehlo()
self.server.login(serverLogin, serverPassword) #login to senders email
self.fromAddr = fromAddr
self.toAddr = toAddr
def send(self):
msgText = email.MIMEText.MIMEText("\n".join(self.message))
self.msg.attach(msgText)
print "Sending email to %s " % self.toAddr
text = self.msg.as_string() #conver the message contents to string format
self.server.sendmail(self.fromAddr, self.toAddr, text) #send the email
Run Code Online (Sandbox Code Playgroud)
邮件测试方法:
def test(self):
message = "Like a …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用python中的smtplib连接到公司的电子邮件服务器,这是我的代码段:
server = smtplib.SMTP('mail.mycompany.com',25)
server.ehlo()
server.starttls()
server.login('my_email@mycompany.com', 'my_password')
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,出现以下错误:
smtplib.SMTPException:服务器不支持STARTTLS扩展。
在Google上搜索此错误后,我发现我公司的smtp服务器不支持starttls身份验证,因此我必须从代码中删除server.starttls()此行,但是当我删除此行时,出现以下错误:
smtplib.SMTPException:服务器不支持SMTP AUTH扩展。
我花了一整天的时间搜索这些错误,但没有找到任何解决方案。
我可以使用此 SO 答案中提供的功能通过 smtplib 发送电子邮件:https : //stackoverflow.com/a/12424439/614770
from __future__ import print_function
def send_email(user, pwd, recipient, subject, body):
import smtplib
FROM = user
TO = recipient if type(recipient) is list else [recipient]
SUBJECT = subject
TEXT = body
# Prepare actual message
message = """From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ', '.join(TO), SUBJECT, TEXT)
try:
server = smtplib.SMTP('smtp.office365.com', 587)
server.ehlo()
server.starttls()
server.login(user, pwd)
server.sendmail(FROM, TO, message)
server.close()
print('Successfully sent the mail')
except:
print('Failed to send mail')
if __name__ == …Run Code Online (Sandbox Code Playgroud) 我没有想法如何解决这个问题.我检查了大多数smtplib线程,那些关于"AttributeError:'tuple'对象没有属性'encode'"
我正在尝试创建消息模板以从Python3脚本发送电子邮件.出于某种原因,当我添加消息模板时,我无法以任何方式解决这个问题.
import smtplib
import additional
import datetime
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
#server commends
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
#credentials of sender
FROM = "xxx.gmail.com"
PASSWORD = additional.x #hidden password in other .py file
#logging in
server.login(FROM, PASSWORD)
#template for recievers
TOADDR = ["reciever email"]
CC = ["FIRST CC", "2ND CC"]
SUBJECT = "testing"
TEXT = "Let's check if this works and I joined everything correctly"
#MSG template
FINAL_TO = CC + [TOADDR]
message …Run Code Online (Sandbox Code Playgroud) 目前,我使用此解决方案Send table as an email body (not attachment ) 在 Python中通过 Python 在电子邮件中发送表格:
import smtplib
from smtplib import SMTPException
import csv
from tabulate import tabulate
text = """
Hello, Friend.
Here is your data:
{table}
Regards,
Me"""
html = """
<html><body><p>Hello, Friend.</p>
<p>Here is your data:</p>
{table}
<p>Regards,</p>
<p>Me</p>
</body></html>
"""
with open('result.csv') as input_file:
reader = csv.reader(input_file)
data = list(reader)
text = text.format(table=tabulate(data, headers="firstrow", tablefmt="grid"))
html = html.format(table=tabulate(data, headers="firstrow", tablefmt="html"))
message = MIMEMultipart(
"alternative", None, [MIMEText(text), MIMEText(html,'html')]) …Run Code Online (Sandbox Code Playgroud) import smtplib
smtp = smtplib.SMTP()
smtp.connect('smtp.gmail.com','587')
(220, b'smtp.gmail.com ESMTP h15-v6sm187291iog.48 - gsmtp')
smtp.starttls()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py", line 771, in starttls
server_hostname=self._host)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 843, in _create
owner=self, session=self._session,
ValueError: server_hostname cannot be an empty string or start with a leading dot.
Run Code Online (Sandbox Code Playgroud)
我在Mac上使用python 3.7,无法与gmail执行tls握手。这段代码适用于python 2.7,以及使用python 3.5.2的Ubuntu服务器。有谁知道是什么原因导致此错误?
到目前为止,我只能发送电子邮件。这是我的代码:
import smtplib
email_user = 'myemail@gmail.com'
server = smtplib.SMTP ('smtp.gmail.com', 587)
server.starttls()
server.login(email_user, 'email pass')
#SET TIME HERE?
from crontab import CronTab
#EMAIL
message = 'sending this from python!'
server.sendmail(email_user, email_user, message)
server.quit()
Run Code Online (Sandbox Code Playgroud)
我正在努力设定发送电子邮件的时间。如果有人也能帮我弄清楚如何添加附件,那就太好了!
我有一个错误,TypeError:预期的类似字节的对象,而不是 NoneType。错误来自:encoders.encode_base64(eml_atch) line 56。
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate
from email import encoders
import os,datetime
CRLF = "\r\n"
login = "my@email.com"
password = "mypassword"
attendees = ["attendees1@gmail.com", "attendees2@gmail.com","attendees3@gmail.com"]
organizer = "ORGANIZER;CN=organiser:mailto:first"+CRLF+" @ada-asia.com"
fro = "Fahim Maula <fahim.maula@ada-asia.com>"
ddtstart = datetime.datetime.now()
dtoff = datetime.timedelta(days = 1)
dur = datetime.timedelta(hours = 1)
ddtstart = ddtstart +dtoff
dtend = ddtstart + dur
dtstamp = datetime.datetime.now().strftime("%Y%m%dT%H%M%SZ")
dtstart = ddtstart.strftime("%Y%m%dT%H%M%SZ")
dtend …Run Code Online (Sandbox Code Playgroud)