email

Sending mail in python

A quick Python function that shows how to send an email.

def send_mail(destination, source, subject, text, smtp_addr='localhost'):
    """Simple function to send an email.
   
    destination
        The email address that the message should be sent to.
    source
        The 'From' address that will be used for the email.
    subject
        The subject/ title of the email.
    text
        The actual message/ content of the email.
    smtp_addr
        The hostname or IP address of the SMTP server that will deliver the
        email.
   
    Example usage:
        send_mail('my_friend@test.com', 'bgates@microsoft.com',
                'Hi!', 'Just checking in.')
   
    "
""
    import email.Message
    import smtplib
    mail = email.Message.Message()
    mail['To'] = destination
    mail['From'] = source
    mail['Subject'] = subject
    mail.set_payload(text)
    server = smtplib.SMTP(smtp_addr)
    server.sendmail(source, destination, mail.as_string())
    server.quit()

Addressing Outlook Express IMAP Timeouts and Disconnects

Ever seen the cryptic "0x800ccc0f" error when trying to synchronize your IMAP folders in Outlook? The rather cryptic Microsoft errors are useless. There are literally hundreds of websites that discuss this issue and damn near everyone of them is also useless. This one is not.

Syndicate content