Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中Sendgrid smtp API中的反弹处理_Python_Email_Smtp_Sendgrid - Fatal编程技术网

Python中Sendgrid smtp API中的反弹处理

Python中Sendgrid smtp API中的反弹处理,python,email,smtp,sendgrid,Python,Email,Smtp,Sendgrid,我通过python EmailMultiAlternations通过sendgrid smtp api发送营销电子邮件。我想知道我如何处理直接从那里反弹来的邮件,将特定的邮件标记为无法投递 代码片段是: def send1(): text_content = 'Hi this is the text version' connection = get_connection(host=EMAIL_HOST, port=

我通过python EmailMultiAlternations通过sendgrid smtp api发送营销电子邮件。我想知道我如何处理直接从那里反弹来的邮件,将特定的邮件标记为无法投递

代码片段是:

def send1():
    text_content = 'Hi this is the text version'
    connection = get_connection(host=EMAIL_HOST,
                                port=EMAIL_PORT,
                                username=EMAIL_HOST_USER,
                                password=EMAIL_HOST_PASSWORD,
                                use_tls=EMAIL_USE_TLS)
    connection.open()
    subject = 'Inviting {0} to join the Business Network of SMEs'.format('surya')
    html_content = template.format('Surya')
    from_email = 'sp@abc.com'
    to = 'abc@gmail.com'
    msg = EmailMultiAlternatives(subject, text_content, from_email, [to], connection=connection)
    msg.attach_alternative(html_content, "text/html")
    msg.send()
    connection.close()

只有在
msg.send()
之后才能在此处获得响应,或者是否有其他方法。

响应块和反弹等事件的最佳方法是实现


您还可以通过轮询获取数据。

响应块和反弹等事件的最佳方法是实现


您还可以通过。

轮询数据。因此,对于那些可能正在寻找解决方案的人:

我每天都在使用imaplibpython包从收件箱(我发送电子邮件的邮箱id)中搜寻被退回的电子邮件和投诉,以获取那些不需要的电子邮件

def bounce():

    M = imaplib.IMAP4_SSL('imap.zoho.com')
    M.login('email@emailcom', password)
    M.select()
    line = '(HEADER Subject "Bounce")'
    typ, data = M.uid('search', line)
    if typ != 'OK':
        return
    print(len(data[0].split()))
    for i in data[0].split():

        result, data = M.uid('fetch', i, '(RFC822)')
        raw_email = data[0][1].decode('utf-8', 'ignore')
        emg = email.message_from_string(raw_email)

        w = get_first_text_block(emg)
        emails = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", str(w), re.I)

因此,每天或每小时执行代码将对您有所帮助。

因此,对于那些可能正在寻找解决方案的人:

我每天都在使用imaplibpython包从收件箱(我发送电子邮件的邮箱id)中搜寻被退回的电子邮件和投诉,以获取那些不需要的电子邮件

def bounce():

    M = imaplib.IMAP4_SSL('imap.zoho.com')
    M.login('email@emailcom', password)
    M.select()
    line = '(HEADER Subject "Bounce")'
    typ, data = M.uid('search', line)
    if typ != 'OK':
        return
    print(len(data[0].split()))
    for i in data[0].split():

        result, data = M.uid('fetch', i, '(RFC822)')
        raw_email = data[0][1].decode('utf-8', 'ignore')
        emg = email.message_from_string(raw_email)

        w = get_first_text_block(emg)
        emails = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", str(w), re.I)
因此,每天或每小时执行代码都会对您有所帮助。

您也可以使用。以下内容是使用版本6.4.1编写的

import sendgrid
sg = sendgrid.SendGridAPIClient(api_key="<your_key>")
payload = {
    "limit": 100,
    "offset": 0,
}
response = sg.client.suppression.bounces.get(query_params=payload)
导入sendgrid
sg=sendgrid.SendGridAPIClient(api_key=”“)
有效载荷={
“限额”:100,
“偏移量”:0,
}
response=sg.client.suppression.bounces.get(查询参数=payload)
可以省略查询参数以接受默认值,还可以使用开始时间和结束时间(需要是整数Unix时间)。

您也可以使用。以下内容是使用版本6.4.1编写的

import sendgrid
sg = sendgrid.SendGridAPIClient(api_key="<your_key>")
payload = {
    "limit": 100,
    "offset": 0,
}
response = sg.client.suppression.bounces.get(query_params=payload)
导入sendgrid
sg=sendgrid.SendGridAPIClient(api_key=”“)
有效载荷={
“限额”:100,
“偏移量”:0,
}
response=sg.client.suppression.bounces.get(查询参数=payload)
可以省略查询参数以接受默认值,还可以使用开始时间和结束时间(需要是整数Unix时间)