Skip to main content

Email Service

Wrapper for the '/email' APIs.

List of all options:

  • Send custom email
  • Send email to a user

Simple email message

from trivoreid.models.email import Email

# send to one email
email = Email()
email.construct_email(to='[email protected]',
from_email='[email protected]',
subject='Subject',
text='Emample text body')

api.email_service.send(email)

# send to multiple emails
email.construct_email(to=['[email protected]', '[email protected]'],
from_email='[email protected]',
subject='Subject',
text='Emample text body')

Advanced options

from trivoreid.models.email import Email, EmailAttachments

attachments = EmailAttachments()
attachments.add_attachment(name='attachment.txt', data=data)
attachments.add_attachment(name='attachment2.txt', data=data2)

email = Email()
email.construct_email(to=['[email protected]', '[email protected]', '[email protected]'],
cc=['[email protected]', '[email protected]', '[email protected]'],
bcc=['[email protected]', '[email protected]', '[email protected]'],
from_email='[email protected]',
reply_to=['[email protected]', '[email protected]', '[email protected]'],
subject='Example subject',
html='Hello <b>there</b>',
attachments=attachments)

api.email_service.send(email)

Send email to a user

from trivoreid.models.email import Email

email = Email()
email.construct_email(from_email='[email protected]',
subject='Subject',
text='Emample text body')

api.email_service.send_to_user(email, userId)

Send email to all group members

Sending email to all primary (first) email addresses of users that belong to the defined groups.

email = Email()
email.text = 'Example text body.'
email.subject = 'Example subject'
email.from_email = '[email protected]'

api.email_service.send_to_group_members(nsCode,
email,
'groupName1', 'groupName2', 'groupName3')

### send email as bcc
api.email_service.send_to_group_members(nsCode,
email,
'groupName4', 'groupName5', 'groupName6',
bcc=True)

Email Service Models

Email

EmailAddress

EmailAttachments