14.2.41. camcops_server.cc_modules.cc_email

camcops_server/cc_modules/cc_email.py


Copyright (C) 2012-2019 Rudolf Cardinal (rudolf@pobox.com).

This file is part of CamCOPS.

CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <http://www.gnu.org/licenses/>.


Email functions/log class.

class camcops_server.cc_modules.cc_email.Email(from_addr='', date=None, sender='', reply_to='', to='', cc='', bcc='', subject='', body='', content_type='text/plain', charset='utf8', attachment_filenames=None, attachments_binary=None, save_msg_string=False)[source]

Class representing an e-mail sent from CamCOPS.

This is abstract, in that it doesn’t care about the purpose of the e-mail. It’s cross-referenced from classes that use it, such as camcops_server.cc_modules.cc_exportmodels.ExportedTaskEmail.

Parameters:
  • from_addr – name of the sender for the “From:” field
  • date – e-mail date in RFC 2822 format, or None for “now”
  • sender – name of the sender for the “Sender:” field
  • reply_to – name of the sender for the “Reply-To:” field
  • to – e-mail address(es) of the recipients for “To:” field, as a CSV list
  • cc – e-mail address(es) of the recipients for “Cc:” field, as a CSV list
  • bcc – e-mail address(es) of the recipients for “Bcc:” field, as a CSV list
  • subject – e-mail subject
  • body – e-mail body
  • content_type – MIME type for body content, default text/plain
  • charset – character set for body; default utf8
  • charset
  • attachment_filenames – filenames of attachments to add
  • attachments_binary – binary attachments to add, as a list of filename, bytes tuples
  • save_msg_string – save the encoded message string? (May take significant space in the database).
init_on_load() → None[source]

Called when SQLAlchemy recreates an object; see https://docs.sqlalchemy.org/en/latest/orm/constructors.html.

send(host: str, username: str, password: str, port: int = None, use_tls: bool = True) → bool[source]

Sends message and returns success.