当前位置: 首页>>代码示例>>Python>>正文


Python utils.formataddr方法代码示例

本文整理汇总了Python中email.utils.formataddr方法的典型用法代码示例。如果您正苦于以下问题:Python utils.formataddr方法的具体用法?Python utils.formataddr怎么用?Python utils.formataddr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在email.utils的用法示例。


在下文中一共展示了utils.formataddr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: addr_header_encode

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def addr_header_encode(text, header_name=None):
    """Encode and line-wrap the value of an email header field containing
    email addresses."""

    # Convert to unicode, if required.
    if not isinstance(text, unicode):
        text = unicode(text, "utf-8")

    text = ", ".join(
        formataddr((header_encode(name), emailaddr))
        for name, emailaddr in getaddresses([text])
    )

    if is_ascii(text):
        charset = "ascii"
    else:
        charset = "utf-8"

    return Header(
        text, header_name=header_name, charset=Charset(charset)
    ).encode() 
开发者ID:Pagure,项目名称:pagure,代码行数:23,代码来源:git_multimail_upstream.py

示例2: sanitize_address

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def sanitize_address(addr, encoding):
    if isinstance(addr, six.string_types):
        addr = parseaddr(force_text(addr))
    nm, addr = addr
    # This try-except clause is needed on Python 3 < 3.2.4
    # http://bugs.python.org/issue14291
    try:
        nm = Header(nm, encoding).encode()
    except UnicodeEncodeError:
        nm = Header(nm, 'utf-8').encode()
    try:
        addr.encode('ascii')
    except UnicodeEncodeError:  # IDN
        if '@' in addr:
            localpart, domain = addr.split('@', 1)
            localpart = str(Header(localpart, encoding))
            domain = domain.encode('idna').decode('ascii')
            addr = '@'.join([localpart, domain])
        else:
            addr = Header(addr, encoding).encode()
    return formataddr((nm, addr)) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:23,代码来源:message.py

示例3: stringify_address

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def stringify_address(address):
    """
    Converts an address into a string in the `"John Doe" <john@example.com>"` format, which can be directly used in the
    headers of an email.

    Parameters
    ----------
    address : str or (str, str)
        An address. Can be either the email address or a tuple of the name
        and the email address.

    Returns
    -------
    str
        Address as a single string, in the `"John Doe" <john@example.com>"` format. Returns
        `address` unchanged if it's a single string.
    """
    address = ('', address) if isinstance(address, str) else address
    return formataddr((str(Header(address[0], 'utf-8')), address[1])) 
开发者ID:SkullTech,项目名称:drymail,代码行数:21,代码来源:drymail.py

示例4: Mail

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def Mail(TO,TITLE,CONTENT):
  ret=True
  my_user = TO
  try:
    msg=MIMEText(CONTENT,'plain','utf-8')
    msg['From']=formataddr(["Kanch's PythonBot @ MyPythonVPS",my_sender])  #括号里的对应发件人邮箱昵称、发件人邮箱账号
    msg['To']=formataddr(["Autosend by bot",my_user])  #收件人邮箱昵称、收件人邮箱账号
    msg['Subject']=TITLE #邮件的主题
 
    server=smtplib.SMTP("smtp.163.com",25) #发件人邮箱中的SMTP服务器,端口是25
    server.login(my_sender,my_sender_password)  #括号中对应的是发件人邮箱账号、邮箱密码
    server.sendmail(my_sender,my_user,msg.as_string())  #括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
    server.quit() 
  except Exception:  
    ret=False
  return ret
 
#SendMail("1075900121@qq.com",'主题','括号中对应的是发件人邮箱账号、括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件邮箱密码') 
开发者ID:ankanch,项目名称:tieba-zhuaqu,代码行数:20,代码来源:MailService.py

示例5: sanitize_address

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def sanitize_address(addr, encoding):
    if isinstance(addr, str):
        addr = parseaddr(addr)
    nm, addr = addr
    nm = Header(nm, encoding).encode()
    try:
        addr.encode('ascii')
    except UnicodeEncodeError:  # IDN
        if '@' in addr:
            localpart, domain = addr.split('@', 1)
            localpart = str(Header(localpart, encoding))
            domain = domain.encode('idna').decode('ascii')
            addr = '@'.join([localpart, domain])
        else:
            addr = Header(addr, encoding).encode()
    return formataddr((nm, addr)) 
开发者ID:quantmind,项目名称:lux,代码行数:18,代码来源:message.py

示例6: sanitize_address

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def sanitize_address(addr, encoding='utf-8'):
    if isinstance(addr, str):
        addr = parseaddr(force_text(addr))
    nm, addr = addr

    try:
        nm = Header(nm, encoding).encode()
    except UnicodeEncodeError:
        nm = Header(nm, 'utf-8').encode()
    try:
        addr.encode('ascii')
    except UnicodeEncodeError:  # IDN
        if '@' in addr:
            localpart, domain = addr.split('@', 1)
            try:
                localpart = Header(localpart, encoding).encode()
            except UnicodeEncodeError:
                localpart = Header(localpart, 'utf-8').encode()
            domain = domain.encode('idna').decode('ascii')
            addr = '@'.join([localpart, domain])
        else:
            addr = Header(addr, encoding).encode()
    return formataddr((nm, addr)) 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:25,代码来源:flask_mail.py

示例7: __init__

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def __init__(self, token, data):
        self.token = token
        self.id = data.get('id', None)
        self.subject = data.get('subject', None)
        self.time = data.get('time', None)
        self.to = data.get('to', None)
        self.seconds_ago = data.get('seconds_ago', None)
        self.ip = data.get('ip')

        try:
            self.origfrom = data['origfrom']
            # Support old Message attributes
            self.fromshort, self.fromfull = parseaddr(self.origfrom)
        except KeyError:
            # Try the old data model
            self.fromfull = data.get('fromfull')
            self.fromshort = data.get('from')
            self.origfrom = formataddr((self.fromshort, self.fromfull))

        self.headers = {}
        self.body = "" 
开发者ID:mc706,项目名称:py-mailinator,代码行数:23,代码来源:wrapper.py

示例8: workflow_script_ready_to_ship

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def workflow_script_ready_to_ship(self):
        #send the email
        lab = self.bika_setup.laboratory
        sender = formataddr((encode_header(lab.getName()), self.getFromEmailAddress()))

        client = self.getClient()
        receiver = formataddr((encode_header(client.getName()), self.getToEmailAddress()))

        samples_text = self.getStringified(self.getSamplesList())

        subject = "Samples ready to ship"
        body = "Automatic email:\n"
        body += 'The samples \"%s\" are ready to ship.' % samples_text

        # print('------------')
        # print(sender)
        # print(receiver)
        # print(body)

        self.send_mail(sender, receiver, subject, body) 
开发者ID:BaobabLims,项目名称:baobab.lims,代码行数:22,代码来源:sampleshipment.py

示例9: workflow_script_dispatch_shipment

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def workflow_script_dispatch_shipment(self):
        """executed after shipment state transition "dispatch"
        """
        # free positions kits occupy
        kits = self.getKits()
        w_tool = getToolByName(self, 'portal_workflow')
        for kit in kits:
            kit.setStorageLocation('')
            w_tool.doActionFor(kit, 'ship')
            kit.reindexObject()

        # Set shipment's date dispatched
        now = DateTime()
        self.setDateDispatched(now)

        to_contact = self.getToContact()
        from_contact = self.getFromContact()
        client = to_contact.aq_parent
        lab = self.bika_setup.laboratory
        subject = "Kits dispatched from {}".format(lab.getName())
        sender = formataddr((lab.getName(), from_contact.getEmailAddress()))
        receiver = formataddr((encode_header(client.getName()), to_contact.getEmailAddress()))
        body = "Automatic email:\n"
        body += 'The shipment \"%s\" has been sent from the Biobank \"%s\".' % (self.Title(), lab.getName())
        self.send_mail(sender, receiver, subject, body) 
开发者ID:BaobabLims,项目名称:baobab.lims,代码行数:27,代码来源:shipment.py

示例10: _format_addr

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def _format_addr(s):
    """
    parse the email sender and receiver, Chinese encode and support

    :param s: eg. 'name <email@website.com>, name2 <email2@web2.com>'
    """
    name, addr = parseaddr(s)
    return formataddr((Header(name, "utf-8").encode(), addr)) 
开发者ID:refraction-ray,项目名称:xalpha,代码行数:10,代码来源:realtime.py

示例11: mail_mainbody

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def mail_mainbody():
    ''' 生成邮件正文内容

    :return: MIMEMultipart()实例
    '''

    message = MIMEMultipart()
    message['From'] = formataddr(["万益能源", sender])  # 发送方昵称
    message['To'] = formataddr(["来福士", touser])  # 接收方昵称
    message['Subject'] = '这是一封提醒11:36'  # 邮件主题
    content='请问您对我们的服务满意吗?'
    message.attach(MIMEText(content, 'plain', 'utf-8'))  # 邮件正文内容
    return message 
开发者ID:EvilPsyCHo,项目名称:TaskBot,代码行数:15,代码来源:sendmail_agent.py

示例12: replace_header_when_reply

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def replace_header_when_reply(msg: Message, alias: Alias, header: str):
    """
    Replace CC or To Reply emails by original emails
    """
    addrs = get_addrs_from_header(msg, header)

    # Nothing to do
    if not addrs:
        return

    new_addrs: [str] = []

    for addr in addrs:
        name, reply_email = parseaddr(addr)

        # no transformation when alias is already in the header
        if reply_email == alias.email:
            continue

        contact = Contact.get_by(reply_email=reply_email)
        if not contact:
            LOG.warning(
                "%s email in reply phase %s must be reply emails", header, reply_email
            )
            # still keep this email in header
            new_addrs.append(addr)
        else:
            new_addrs.append(formataddr((contact.name, contact.website_email)))

    new_header = ",".join(new_addrs)
    LOG.d("Replace %s header, old: %s, new: %s", header, msg[header], new_header)
    add_or_replace_header(msg, header, new_header) 
开发者ID:simple-login,项目名称:app,代码行数:34,代码来源:email_handler.py

示例13: website_send_to

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def website_send_to(self):
        """return the email address with name.
        to use when user wants to send an email from the alias
        Return
        "First Last | email at example.com" <ra+random_string@SL>
        """

        # Prefer using contact name if possible
        name = self.name

        # if no name, try to parse it from website_from
        if not name and self.website_from:
            try:
                from app.email_utils import parseaddr_unicode

                name, _ = parseaddr_unicode(self.website_from)
            except Exception:
                # Skip if website_from is wrongly formatted
                LOG.warning(
                    "Cannot parse contact %s website_from %s", self, self.website_from
                )
                name = ""

        # remove all double quote
        if name:
            name = name.replace('"', "")

        if name:
            name = name + " | " + self.website_email.replace("@", " at ")
        else:
            name = self.website_email.replace("@", " at ")

        # cannot use formataddr here as this field is for email client, not for MTA
        return f'"{name}" <{self.reply_email}>' 
开发者ID:simple-login,项目名称:app,代码行数:36,代码来源:models.py

示例14: new_addr

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def new_addr(self):
        """
        Replace original email by reply_email. Possible formats:
        - first@example.com via SimpleLogin <reply_email> OR
        - First Last - first at example.com <reply_email> OR
        - First Last - first(a)example.com <reply_email> OR
        - First Last - first@example.com <reply_email> OR
        And return new address with RFC 2047 format

        `new_email` is a special reply address
        """
        user = self.user
        if (
            not user
            or not SenderFormatEnum.has_value(user.sender_format)
            or user.sender_format == SenderFormatEnum.VIA.value
        ):
            new_name = f"{self.website_email} via SimpleLogin"
        elif user.sender_format == SenderFormatEnum.AT.value:
            name = self.name or ""
            new_name = (
                name + (" - " if name else "") + self.website_email.replace("@", " at ")
            ).strip()
        elif user.sender_format == SenderFormatEnum.A.value:
            name = self.name or ""
            new_name = (
                name + (" - " if name else "") + self.website_email.replace("@", "(a)")
            ).strip()
        elif user.sender_format == SenderFormatEnum.FULL.value:
            name = self.name or ""
            new_name = (name + (" - " if name else "") + self.website_email).strip()

        new_addr = formataddr((new_name, self.reply_email)).strip()
        return new_addr.strip() 
开发者ID:simple-login,项目名称:app,代码行数:36,代码来源:models.py

示例15: set_recipients

# 需要导入模块: from email import utils [as 别名]
# 或者: from email.utils import formataddr [as 别名]
def set_recipients(self, name, value):
        self.unset_all(name)
        for pair in getaddresses([value]):
            self.add(name, formataddr(pair)) 
开发者ID:Pagure,项目名称:pagure,代码行数:6,代码来源:git_multimail_upstream.py


注:本文中的email.utils.formataddr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。