Send an email (via TLS when username and password are specified)

    Parameters
    ----------
    msg : object
        An instance of MIMEText. Create this with :func:`create_message`
        function.
    host : string
        A mail user agent host name (Default: localhost)
    port : int
        A mail user agent port number (Default: 25)
    username : string
        A username string used to login MUA via TLS authentication
    password : string
        A password string used to login MUA via TLS authentication
    debug : boolean
        True for displaying debug messages

def send_email(msg, host='localhost', port=25,
         username=None, password=None):
    """
    Send an email (via TLS when username and password are specified)

    Parameters
    ----------
    msg : object
        An instance of MIMEText. Create this with :func:`create_message`
        function.
    host : string
        A mail user agent host name (Default: localhost)
    port : int
        A mail user agent port number (Default: 25)
    username : string
        A username string used to login MUA via TLS authentication
    password : string
        A password string used to login MUA via TLS authentication
    debug : boolean
        True for displaying debug messages
    """
    s = smtplib.SMTP(host, port)
    if username and password:
        s.ehlo()
        s.starttls()
        s.ehlo()
        s.login(user, passwd)
    s.sendmail(msg['From'], [msg['To']], msg.as_string())
    s.close()