1.1.2.13. gnr.core.gnrmailhandler

Last page update: November 23, 2011

Classes:

External methods:

Complete reference:

1.1.2.13.2. External methods

These methods don’t belong to any class.

1.1.2.13.3. gnr.core.gnrmailhandler - The complete reference list

class gnr.core.gnrmailhandler.MailHandler(parent=None)

A class for mail management.

build_base_message(subject, body, attachments=None, html=None, charset=None)

Add???

Parameters:
  • subject – the email subject
  • body – the email body. If you pass html=True attribute, then you can pass in the body the html tags
  • attachments – path of the attachment to be sent with the email
  • html – TODO
  • charset – a different charser may be defined by its standard name
get_account_params(account=None, from_address=None, smtp_host=None, port=None, user=None, password=None, ssl=False, tls=False, **kwargs)

Set the account parameters and return them

Parameters:
  • account – if an account has been defined previously with set_smtp_account() then this account can be used instead of having to repeat all the mail parameters contained
  • from_address – the email sender
  • smtp_host – the smtp host to send this email
  • port – if a non standard port is used then it can be overridden
  • user – the username
  • password – the username’s password
  • ssl – boolean. If True, attempt to use the ssl port. Else standard smtp port is used
  • tls

    boolean. Allow to communicate with an smtp server. You may choose three ways:

    1. no encryption
    2. ssl -> all data is encrypted on a ssl layer
    3. tls -> server and client begin communitation in a unsecure way and after a starttls command they start to encrypt data (this is the way you use to connect to gmail smtp)
get_smtp_connection(account=None, smtp_host=None, port=None, user=None, password=None, ssl=False, tls=False, **kwargs)

Get the smtp connection and return it

Parameters:
  • account – if an account has been defined previously with set_smtp_account() then this account can be used instead of having to repeat all the mail parameters contained
  • smtp_host – the smtp host to send this email
  • port – if a non standard port is used then it can be overridden
  • user – the username
  • password – the username’s password
  • ssl – boolean. If True, attempt to use the ssl port. Else standard smtp port is used.
  • tls

    allow to communicate with an smtp server. You may choose three ways:

    1. no encryption
    2. ssl -> all data is encrypted on a ssl layer
    3. tls -> server and client begin communitation in a unsecure way and after a starttls command they start to encrypt data (this is the way you use to connect to gmail smtp)
handle_addresses(from_address=None, to_address=None, multiple_mode=None)

Handle the mail addresses and return them as a list

Parameters:
  • from_address – the email sender
  • to_address – the email receiver
  • multiple_mode – TODO
sendmail(to_address=None, subject=None, body=None, cc_address=None, bcc_address=None, attachments=None, account=None, from_address=None, smtp_host=None, port=None, user=None, password=None, ssl=False, tls=False, html=False, charset='utf-8', async=False, **kwargs)

Send mail is a function called from the postoffice object to send an email.

Parameters:
  • to_address – the email receiver
  • subject – the email subject
  • body – the email body. If you pass html=True attribute, then you can pass in the body the html tags
  • cc_address – can be a comma deliminated str of email addresses or a list or tuple.
  • bcc_address – can be a comma deliminated str of email addresses or a list or tuple.
  • attachments – path of the attachment to be sent with the email
  • account – if an account has been defined previously with set_smtp_account() then this account can be used instead of having to repeat all the mail parameters contained
  • from_address – the email sender
  • smtp_host – the smtp host to send this email
  • port – if a non standard port is used then it can be overridden
  • user – the username
  • password – the username’s password
  • ssl – boolean. If True, attempt to use the ssl port. Else standard smtp port is used
  • tls

    allow to communicate with an smtp server. You may choose three ways:

    1. no encryption
    2. ssl -> all data is encrypted on a ssl layer
    3. tls -> server and client begin communitation in a unsecure way and after a starttls command they start to encrypt data (this is the way you use to connect to gmail smtp)
  • html – boolean. If True then html tags can be used in the body of the email. Appropriate headers are attached
  • charset – a different charser may be defined by its standard name
  • async – if set to true, then a separate process is spawned to send the email and control is returned immediately to the calling function
sendmail_many(to_address, subject, body, attachments=None, account=None, from_address=None, smtp_host=None, port=None, user=None, password=None, ssl=False, tls=False, html=False, multiple_mode=False, progress_cb=None, charset='utf-8', async=False)

TODO

Parameters:
  • to_address – the email receiver
  • subject – the email subject
  • body – the email body. If you pass html=True attribute, then you can pass in the body the html tags
  • attachments – path of the attachment to be sent with the email.
  • account – if an account has been defined previously with set_smtp_account() then this account can be used instead of having to repeat all the mail parameters contained
  • from_address – the email sender
  • smtp_host – the smtp host to send this email
  • port – if a non standard port is used then it can be overridden
  • user – the username
  • password – the username’s password
  • ssl – boolean. If True, attempt to use the ssl port. Else standard smtp port is used
  • tls

    allow to communicate with an smtp server. You may choose three ways:

    1. no encryption
    2. ssl -> all data is encrypted on a ssl layer
    3. tls -> server and client begin communitation in a unsecure way and after a starttls command they start to encrypt data (this is the way you use to connect to gmail smtp)
  • html – boolean. If True, html tags can be used in the body of the email. Appropriate headers are attached
  • multiple_mode

    allow to send a mail to many addresses. Its parameters are:

    • False - single mail for recipient
    • to, To, TO - a mail sent to all recipient in to field
    • bcc, Bcc, BCC - a mail sent to ourself with all recipient in bcc address
  • charset – a different charser may be defined by its standard name
sendmail_template(datasource, to_address=None, cc_address=None, bcc_address=None, subject=None, from_address=None, body=None, attachments=None, account=None, smtp_host=None, port=None, user=None, password=None, ssl=False, tls=False, html=False, charset='utf-8', async=False, **kwargs)

Add???

Parameters:
  • datasource – TODO
  • to_address – the email receiver
  • cc_address – can be a comma deliminated str of email addresses or a list or tuple
  • bcc_address – can be a comma deliminated str of email addresses or a list or tuple
  • subject – the email subject
  • from_address – the email sender
  • body – the email body. If you pass html=True attribute, then you can pass in the body the html tags
  • attachments – path of the attachment to be sent with the email
  • account – if an account has been defined previously with set_smtp_account() then this account can be used instead of having to repeat all the mail parameters contained
  • smtp_host – the smtp host to send this email
  • port – if a non standard port is used then it can be overridden
  • user – the username
  • password – the username’s password
  • ssl – boolean. If True, attempt to use the ssl port. Else standard smtp port is used
  • tls

    allow to communicate with an smtp server.

    You may choose three ways:

    1. no encryption
    2. ssl -> all data is encrypted on a ssl layer
    3. tls -> server and client begin communitation in a unsecure way and after a starttls command they start to encrypt data (this is the way you use to connect to gmail smtp)
  • html – boolean. If True, html tags can be used in the body of the email. Appropriate headers are attached
  • charset – a different charser may be defined by its standard name
  • async – boolean. If True, then a separate process is spawned to send the email and control is returned immediately to the calling function
set_imap_default_account(name)

Allow to use the saved account parameters for the subsequent IMAP mails

Parameters:name – the default account’s name
set_pop_default_account(name)

Allow to use the saved account parameters for the subsequent POP mails

Parameters:name – the default account’s name
set_smtp_account(name, from_address=None, smtp_host=None, username=None, password=None, port=None, ssl=False, default=False)

Set the smtp account

Parameters:
  • name – the account’s name
  • from_address – the email sender
  • smtp_host – the smtp host to send this email
  • username – the username
  • password – the username’s password
  • port – if a non standard port is used then it can be overridden
  • ssl – boolean. If True, attempt to use the ssl port. Else standard smtp port is used.
  • default – boolean. TODO
set_smtp_default_account(name)

Allow to use the saved account parameters for the subsequent SMTP mails

Parameters:name – the default account’s name
gnr.core.gnrmailhandler.clean_and_unescape(text)

Removes HTML or XML character references and entities from a text string. Return the plain text, as a Unicode string, if necessary

Parameters:text – The HTML (or XML) source text.