标签: smtplib

如何使用smtplib验证Python中的电子邮件地址

我一直在尝试验证用户在我的程序中输入的电子邮件地址.我目前的代码是:

server = smtplib.SMTP()
server.connect()
server.set_debuglevel(True)
try:
    server.verify(email)
except Exception:
    return False
finally:
    server.quit()
Run Code Online (Sandbox Code Playgroud)

但是,当我运行它时,我得到:

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
Run Code Online (Sandbox Code Playgroud)

所以我要问的是如何使用smtp模块验证电子邮件地址?我想检查电子邮件地址是否确实存在.

python email email-validation smtplib

7
推荐指数
1
解决办法
2万
查看次数

附件在python中使用smptplib连接两次

我试图在python中实现一个功能,我想发送一个文件作为电子邮件提醒的附件一切正常.我收到了所需主题的电子邮件提醒,但唯一的问题是我在电子邮件提醒中两次获得相同的附件.

    fileMsg = email.mime.base.MIMEBase('application','octet-stream')
    fileMsg.set_payload(file('/home/bsingh/python_files/file_dict.txt').read())
    #email.encoders.encode_base64(fileMsg)
    fileMsg.add_header('Content-Disposition','attachment;filename=LogFile.txt')
    emailMsg.attach(fileMsg)

  # send email
    server = smtplib.SMTP(smtp_server)
    server.starttls()
    server.login(username, password)
    server.sendmail(from_add, to_addr,emailMsg.as_string())
    server.quit()
Run Code Online (Sandbox Code Playgroud)

python smtplib

7
推荐指数
2
解决办法
800
查看次数

如何在ubuntu os中安装python smtplib模块

我试图通过pip安装python模块,但它没有成功.任何人都可以帮我在ubuntu 12.10操作系统中安装smtplib python模块吗?

python module smtplib

7
推荐指数
2
解决办法
3万
查看次数

邮件失败; [SSL:UNKNOWN_PROTOCOL]未知协议(_ssl.c:645)

这是一个关于通过经过身份验证的SMTP(而非gmail)发送电子邮件的问题.下面的脚本通过本网站上的各种问题和答案汇总在一起,但是我得到的错误是没有"googlable"候选人用于这个特定的工具组合.我在Python 3.5.1中工作,它产生了这个错误:

邮件失败; [SSL:UNKNOWN_PROTOCOL]未知协议(_ssl.c:645)

这是客户端错误还是服务器?我错过了一些我不知道的证书吗?AFAIK服务器支持SSL身份验证.任何想法和推动正确的方向将不胜感激.

import sys
from smtplib import SMTP_SSL as SMTP
from email.mime.text import MIMEText

# credentials masked, obviously
SMTPserver = 'myserver'
sender = 'mymail'
destination = ['recipient']

USERNAME = "myusername"
PASSWORD = "mypass"

# typical values for text_subtype are plain, html, xml
text_subtype = 'plain'

content = """\
Test message
"""

subject = "Sent from Python"

try:
    msg = MIMEText(content, text_subtype)
    msg['Subject'] = subject
    msg['From'] = sender
    conn = SMTP(host=SMTPserver, port=465)
    conn.set_debuglevel(False)
    conn.login(USERNAME, PASSWORD)

    try:
        conn.sendmail(sender, destination, …
Run Code Online (Sandbox Code Playgroud)

python email ssl smtplib python-3.x

7
推荐指数
2
解决办法
1万
查看次数

检测Python smtplib中的退回电子邮件

我正在尝试捕获所有通过Python中的smtplib发送它们时反弹的电子邮件.我查看了这个类似的帖子,建议添加一个异常捕获器,但我注意到我的sendmail函数不会抛出任何例外,即使是假的电子邮件地址.

这是我send_email使用的功能smtplib.

def send_email(body, subject, recipients, sent_from="myEmail@server.com"):
    msg = MIMEText(body)

    msg['Subject'] = subject
    msg['From'] = sent_from
    msg['To'] = ", ".join(recipients)

    s = smtplib.SMTP('mySmtpServer:Port')
    try:
       s.sendmail(msg['From'], recipients, msg.as_string())
    except SMTPResponseException as e:
        error_code = e.smtp_code
        error_message = e.smtp_error
        print("error_code: {}, error_message: {}".format(error_code, error_message))
    s.quit()
Run Code Online (Sandbox Code Playgroud)

示例电话:

send_email("Body-Test", "Subject-Test", ["fakejfdklsa@jfdlsaf.com"], "myemail@server.com")
Run Code Online (Sandbox Code Playgroud)

由于我将发件人设置为自己,因此我可以在发件人的收件箱中收到电子邮件退回报告:

<fakejfdklsa@jfdlsaf.com>: Host or domain name not found. Name service error
    for name=jfdlsaf.com type=A: Host not found

Final-Recipient: rfc822; fakejfdklsa@jfdlsaf.com
Original-Recipient: rfc822;fakejfdklsa@jfdlsaf.com
Action: failed …
Run Code Online (Sandbox Code Playgroud)

python email mime smtp smtplib

7
推荐指数
1
解决办法
1491
查看次数

在python中的电子邮件的from字段中添加发件人姓名

我正在尝试使用以下代码发送电子邮件.

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 send email"
    finally:
        s.quit()


cont = """\
   <html>
     <head></head>
     <body>
       <p>Hi!<br>
          How are you?<br>
          Here is the <a href="http://www.google.com">link</a> you wanted.
       </p>
     </body>
   </html> …
Run Code Online (Sandbox Code Playgroud)

python email smtplib

7
推荐指数
2
解决办法
1万
查看次数

使用 Python 向邮件列表发送电子邮件

我正在努力检查为什么会发生这种情况,但不确定它是在 gmail 的服务器端还是在我正在使用的脚本的一部分中。问题是我正在尝试将电子邮件发送到邮件列表(我发现许多帖子解释如何包含各种电子邮件,但没有解释是否存在将其发送到包含多个地址的单个电子邮件的限制或解决方法) 。

在这种情况下,我想将电子邮件发送给我们公司 BI 团队的许多不同人员 (bi@company.com),通常向此地址发送电子邮件将导致团队中的每个人都收到电子邮件,但是我无法让我工作,而且我不想将所有电子邮件都包含在列表中,因为数量太多,每次都必须手动更改。

当我用另一个单人电子邮件尝试此操作时,效果非常好

    import smtplib    

    sender = 'server@company.com'
    receivers = ['bi@company.com']
    q = ""

    message = """From: Error alert <Server-company>
    To: BI <bi@company.com>
    Subject: Error e-mail

    %s
    """ % q

    try:
        smtpObj = smtplib.SMTP('localhost')
        smtpObj.sendmail(sender, receivers, message)
        print "Successfully sent email"
    except SMTPException:
       print "Error: unable to send email"
Run Code Online (Sandbox Code Playgroud)

python mailing-list smtplib

6
推荐指数
1
解决办法
1万
查看次数

如何从tkinter中的不同类访问变量?

我一直在搜索很多,但我仍然不知道如何从python中的不同类中访问变量.在这种情况下,我想self.vPageOne类到PageTwo类访问变量.

这是我的代码.

import tkinter as tk
import smtplib

TITLE_FONT = ("Helvetica", 18, "bold")

class SampleApp(tk.Tk):

    def __init__(self):
        tk.Tk.__init__(self)

        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}
        for F in (StartPage, PageOne, PageTwo):
            frame = F(container, self)
            self.frames[F] = frame

            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(StartPage)

    def show_frame(self, c):
        frame = self.frames[c]
        frame.tkraise()

class StartPage(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="PyMail",foreground = "Red", font=("Courier", 30, "bold"))
        label.pack(side="top")
        sublabel …
Run Code Online (Sandbox Code Playgroud)

python user-interface tkinter smtplib python-3.x

6
推荐指数
1
解决办法
1万
查看次数

安装 anaconda (smtplib) 中没有的 python 包

我在 linux 上使用 anaconda,我想安装smtplib以发送邮件。我试过了,

conda install smtplib 返回:

PackageNotFoundError: Package missing in current linux-64 channels: - smtplib , 和,

pip install smtplib 返回:

Could not find a version that satisfies the requirement smtplib (from versions: ) No matching distribution found for smtplib

我发现它smtplib在标准 python 发行版中是默认的,我想知道为什么它在 anaconda 中不可用。

问题:如何安装smtplib?或者更笼统地说,如何安装 anaconda 中未包含的软件包?

这里这里有类似的问题,但没有任何答案。


规格Python 2.7.13 |Anaconda 4.3.1 (64-bit)| (default, Dec 20 2016, 23:09:15) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2

python email pip smtplib anaconda

6
推荐指数
1
解决办法
2万
查看次数

如何在不登录服务器的情况下在 Python 中发送电子邮件

我想在没有登录 Python 服务器的情况下发送电子邮件。我正在使用 Python 3.6。我尝试了一些代码,但收到一个错误。这是我的代码:

import smtplib                          

smtpServer='smtp.yourdomain.com'      
fromAddr='from@Address.com'         
toAddr='to@Address.com'     
text= "This is a test of sending email from within Python."
server = smtplib.SMTP(smtpServer)
server.set_debuglevel(1)         
server.sendmail(fromAddr, toAddr, text) 
server.quit()
Run Code Online (Sandbox Code Playgroud)

我希望应该在不询问用户 ID 和密码的情况下发送邮件但收到错误:

"smtplib.SMTPSenderRefused: (530, b'5.7.1 客户端未通过身份验证', 'from@Address.com')"

smtplib python-3.x

6
推荐指数
3
解决办法
2万
查看次数