Allura/allura/tasks/mail_tasks.py
def sendmail(fromaddr, destinations, text, reply_to, subject,
             message_id, in_reply_to=None, sender=None, references=None):
    '''
    Send an email to the specified list of destinations with respect to the preferred email format specified by user.
    It is best for broadcast messages.

    :param fromaddr: ObjectId or str(ObjectId) of user, or email address str

    '''
    from allura import model as M
    addrs_plain = []
    addrs_html = []
    addrs_multi = []
    if fromaddr is None:
        fromaddr = g.noreply
    elif not isinstance(fromaddr, basestring) or '@' not in fromaddr:
        log.warning('Looking up user with fromaddr: %s', fromaddr)
        user = M.User.query.get(_id=ObjectId(fromaddr), disabled=False, pending=False)
        if not user:
            log.warning('Cannot find user with ID: %s', fromaddr)
            fromaddr = g.noreply
        else:
            fromaddr = user.email_address_header()
    # Divide addresses based on preferred email formats
    for addr in destinations:
        if mail_util.isvalid(addr):
            addrs_plain.append(addr)
        else:
            try:
                user = M.User.query.get(_id=ObjectId(addr), disabled=False, pending=False)
                if not user:
                    log.warning('Cannot find user with ID: %s', addr)
                    continue
            except:
                log.exception('Error looking up user with ID: %r' % addr)
                continue
            addr = user.email_address_header()
            if not addr and user.email_addresses:
                addr = user.email_addresses[0]
                log.warning(
                    'User %s has not set primary email address, using %s',
                    user._id, addr)
            if not addr:
                log.error(
                    "User %s (%s) has not set any email address, can't deliver",
                    user._id, user.username)
                continue
            if user.get_pref('email_format') == 'plain':
                addrs_plain.append(addr)
            elif user.get_pref('email_format') == 'html':
                addrs_html.append(addr)
            else:
                addrs_multi.append(addr)
    htmlparser = HTMLParser.HTMLParser()
    plain_msg = mail_util.encode_email_part(htmlparser.unescape(text), 'plain')
    html_text = g.forge_markdown(email=True).convert(text)
    html_msg = mail_util.encode_email_part(html_text, 'html')
    multi_msg = mail_util.make_multipart_message(plain_msg, html_msg)
    smtp_client.sendmail(
        addrs_multi, fromaddr, reply_to, subject, message_id,
        in_reply_to, multi_msg, sender=sender, references=references)
    smtp_client.sendmail(
        addrs_plain, fromaddr, reply_to, subject, message_id,
        in_reply_to, plain_msg, sender=sender, references=references)
    smtp_client.sendmail(
        addrs_html, fromaddr, reply_to, subject, message_id,
        in_reply_to, html_msg, sender=sender, references=references)

    Send an email to the specified list of destinations with respect to the preferred email format specified by user.
    It is best for broadcast messages.

    :param fromaddr: ObjectId or str(ObjectId) of user, or email address str

    
Send an email to the specified list of destinations with respect to the preferred email format specified by user.
It is best for broadcast messages.
Send an email to the specified list of destinations with respect to the preferred email format specified by user . It is best for broadcast messages .
def sendmail(fromaddr, destinations, text, reply_to, subject,
             message_id, in_reply_to=None, sender=None, references=None):
    from allura import model as M
    addrs_plain = []
    addrs_html = []
    addrs_multi = []
    if fromaddr is None:
        fromaddr = g.noreply
    elif not isinstance(fromaddr, basestring) or '@' not in fromaddr:
        log.warning('Looking up user with fromaddr: %s', fromaddr)
        user = M.User.query.get(_id=ObjectId(fromaddr), disabled=False, pending=False)
        if not user:
            log.warning('Cannot find user with ID: %s', fromaddr)
            fromaddr = g.noreply
        else:
            fromaddr = user.email_address_header()
    for addr in destinations:
        if mail_util.isvalid(addr):
            addrs_plain.append(addr)
        else:
            try:
                user = M.User.query.get(_id=ObjectId(addr), disabled=False, pending=False)
                if not user:
                    log.warning('Cannot find user with ID: %s', addr)
                    continue
            except:
                log.exception('Error looking up user with ID: %r' % addr)
                continue
            addr = user.email_address_header()
            if not addr and user.email_addresses:
                addr = user.email_addresses[0]
                log.warning(
                    'User %s has not set primary email address, using %s',
                    user._id, addr)
            if not addr:
                log.error(
                    "User %s (%s) has not set any email address, can't deliver",
                    user._id, user.username)
                continue
            if user.get_pref('email_format') == 'plain':
                addrs_plain.append(addr)
            elif user.get_pref('email_format') == 'html':
                addrs_html.append(addr)
            else:
                addrs_multi.append(addr)
    htmlparser = HTMLParser.HTMLParser()
    plain_msg = mail_util.encode_email_part(htmlparser.unescape(text), 'plain')
    html_text = g.forge_markdown(email=True).convert(text)
    html_msg = mail_util.encode_email_part(html_text, 'html')
    multi_msg = mail_util.make_multipart_message(plain_msg, html_msg)
    smtp_client.sendmail(
        addrs_multi, fromaddr, reply_to, subject, message_id,
        in_reply_to, multi_msg, sender=sender, references=references)
    smtp_client.sendmail(
        addrs_plain, fromaddr, reply_to, subject, message_id,
        in_reply_to, plain_msg, sender=sender, references=references)
    smtp_client.sendmail(
        addrs_html, fromaddr, reply_to, subject, message_id,
        in_reply_to, html_msg, sender=sender, references=references)
def sendmail ( fromaddr , destinations , text , reply_to , subject , message_id , in_reply_to = None , sender = None , references = None ) : from allura import model as M addrs_plain = [ ] addrs_html = [ ] addrs_multi = [ ] if fromaddr is None : fromaddr = g . noreply elif not isinstance ( fromaddr , basestring ) or '@' not in fromaddr : log . warning ( 'Looking up user with fromaddr: %s' , fromaddr ) user = M . User . query . get ( _id = ObjectId ( fromaddr ) , disabled = False , pending = False ) if not user : log . warning ( 'Cannot find user with ID: %s' , fromaddr ) fromaddr = g . noreply else : fromaddr = user . email_address_header ( ) for addr in destinations : if mail_util . isvalid ( addr ) : addrs_plain . append ( addr ) else : try : user = M . User . query . get ( _id = ObjectId ( addr ) , disabled = False , pending = False ) if not user : log . warning ( 'Cannot find user with ID: %s' , addr ) continue except : log . exception ( 'Error looking up user with ID: %r' % addr ) continue addr = user . email_address_header ( ) if not addr and user . email_addresses : addr = user . email_addresses [ 0 ] log . warning ( 'User %s has not set primary email address, using %s' , user . _id , addr ) if not addr : log . error ( "User %s (%s) has not set any email address, can't deliver" , user . _id , user . username ) continue if user . get_pref ( 'email_format' ) == 'plain' : addrs_plain . append ( addr ) elif user . get_pref ( 'email_format' ) == 'html' : addrs_html . append ( addr ) else : addrs_multi . append ( addr ) htmlparser = HTMLParser . HTMLParser ( ) plain_msg = mail_util . encode_email_part ( htmlparser . unescape ( text ) , 'plain' ) html_text = g . forge_markdown ( email = True ) . convert ( text ) html_msg = mail_util . encode_email_part ( html_text , 'html' ) multi_msg = mail_util . make_multipart_message ( plain_msg , html_msg ) smtp_client . sendmail ( addrs_multi , fromaddr , reply_to , subject , message_id , in_reply_to , multi_msg , sender = sender , references = references ) smtp_client . sendmail ( addrs_plain , fromaddr , reply_to , subject , message_id , in_reply_to , plain_msg , sender = sender , references = references ) smtp_client . sendmail ( addrs_html , fromaddr , reply_to , subject , message_id , in_reply_to , html_msg , sender = sender , references = references )
Send an email to the specified list of destinations with respect to the preferred email format specified by user.
Send an email to the specified list of destinations with respect to the preferred email format specified by user .
'''
    Send an email to the specified list of destinations with respect to the preferred email format specified by user.
    It is best for broadcast messages.

    :param fromaddr: ObjectId or str(ObjectId) of user, or email address str

    ''' # Divide addresses based on preferred email formats
fromaddr
ObjectId or str(ObjectId) of user, or email address str
ObjectId or str ( ObjectId ) of user or email address str
destinations
text
reply_to
subject
message_id
in_reply_to
sender
references