Class Email
Class for representing and sending emails.
Syntax
Examples
Email e;
e.setValue("from", "bob@example.com");
e.setValue("to", "allice@example.com");
e.setValue("to", "simon@example.com"); // Value must be set once for each recipient
e.setValue("subject", "test");
e.setValue("body", "This is a test.");
Constructors
Email()
Initializes a new instance of the Email class.
Declaration
Email
Examples
Email e;
e.setValue("from", "bob@example.com");
e.setValue("to", "allice@example.com");
e.setValue("to", "simon@example.com"); // Value must be set once for each recipient
e.setValue("subject", "test");
e.setValue("body", "This is a test.");
Methods
addAttachment(Integer,Bool)
Adds an attachment to the email object.
Declaration
String addAttachment(Integer attachmentId, Bool inline)
Parameters
Type | Name | Description |
---|---|---|
Integer | attachmentId | The database ID of the attachment to include inline Set to true if you want to show the attachment inside the mail (used mostly for images). |
Bool | inline | If true, attachments will be inlined in the email body. |
Returns
Type | Description |
---|---|
String | The ID of the attachment relative to the email. |
Examples
Email e;
e.setValue("from", "bob@example.com");
e.setValue("to", "allice@example.com");
e.setValue("to", "simon@example.com"); // Value must be set once for each recipient
e.setValue("subject", "test");
e.setValue("body", "This is a test.");
send()
Sends the email.
Declaration
Void send()
Returns
Type | Description |
---|---|
Void |
Examples
Email e;
e.setValue("from", "bob@example.com");
e.setValue("to", "allice@example.com");
e.setValue("to", "simon@example.com"); // Value must be set once for each recipient
e.setValue("subject", "test");
e.setValue("body", "This is a test.");
setValue(String,String)
Sets the value of the given field in the email instance.
For multiple recipients, call setValue multiple times, once for each recipient.Declaration
Void setValue(String name, String value)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name of the field. |
String | value | The value to set. |
Returns
Type | Description |
---|---|
Void |
Remarks
Available fields:
- from: The from address.
- to: The recipient.
- cc: The carbon copy recipient.
- bcc: The bcc recipient.
- sms: A cellphone number to send sms to.
- smsFrom: The from address when sending sms.
- subject: The subject of the email.
- body: The plain text body of the email.
- bodyHtml: The HTML formated body of the email.
- ticketId: The ticketId, only used with sms.</p
From version 8.1 any other header value may also be added, for example setValue("X-Foo", "42");
Examples
Email e;
e.setValue("from", "bob@example.com");
e.setValue("to", "allice@example.com");
e.setValue("to", "simon@example.com"); // Value must be set once for each recipient
e.setValue("subject", "test");
e.setValue("body", "This is a test.");