Email

A component designed to send emails.

Component modes: Batch | Legacy

Component mode: Batch

Send mail from queues.

You most commonly use this component as a menu item job that runs continuously.

graph TD start(Start)-->getbatch getbatch[<a href=#sql-sql-call-e-mails>SQL Call: E-mails</a><br>Get a batch to send] getbatch--Procedure returned an<br>empty batch-->stop getbatch--Procedure returned messages-->sendmail sendmail[Send next message in batch] sent[<a href=#sql-sql-call-e-mail-sent>SQL Call: E-mail sent</a><br>Report success] failed[<a href=#sql-sql-call-e-mail-failed>SQL Call: E-mail failed</a><br>Report failure] sendmail--On failure-->failed sendmail--On success-->sent havemore{Have all messages<br>in the batch been<br>processed?} sent & failed --> havemore havemore--Yes-->getbatch havemore--No-->sendmail stop(Stop)

System Settings

The components uses system settings listed under the SMTP heading.

SMTPRelay is the most important, and is the address of the mail server.

SMTPLibrary lets you choose between

  • System.Net.Mail: Legacy mail library.
  • MailKit: More modern, and compatible with more mail servers.
  • Graph: Instead of sending mail over SMTP, send it through Microsoft.Graph.

Go to Admin > Local Settings in your system for a full list of settings.

Component settings

Maximum runtime
The duration in minutes after which the component stops asking for additional email messages to send. The accepted range is 2 to 15 minutes. Leave empty to use default setting of 10 minutes.

SQL

SQL Call: E-mails (mandatory)

Statement to extract e-mail information. Each row in the first resultset corresponds to an e-mail. Each row in the remaining resultsets corresponds to an attachment, and all attachments are attached to all e-mails.

The component will make this call repeatedly until it reaches maxminutes or receives an empty resultset.

May modify database: Yes

Parameters

@StartTime datetime
Gives the point in time when the batchemail component started running and should be used to avoid trying to send the same e-mail message more than once during the same menuitem execution.

A good practice is to have a column with the name "DatetimeLastSendAttempt" (or similar) in your e-mail queue. In the stored procedure call where you feed the component with messages to send, you should only pick messages where DatetimeLastSendAttempt < @StartTime and then update DatetimeLastSendAttempt to GETDATE() for those messages before returning control back to the component.

Resultset: E-mail data

Resultset that contains e-mail data.
Table count: repeated exactly once
Row count: zero or more rows
Columns
Alternative_PlainText optional bit
Used when sending e-mails that contains both an html and plain text version of the body. Use this column to specify that a plain text version of the message should automatically be generated from the html body.

The plain text version will contain the same text as the html message but with all html tags removed except <br> and <p> tags, which will be replaced by newlines.
Bcc optional string
The 'bcc' property in the email, if it contains more than 1 address then the addresses need to be separated with ';'.
Only addresses containing standard 7-bit ASCII-characters are supported (thus the characters åäö are not supported).
Body optional string
The 'body' property in the email. If this is an html e-mail the contents of this column will be inserted within the <body> section of the html document. You should not include your own <html>, <head> or <body> tags in this column. If this column is null it will be ignored.
Body_Html optional string
Used when sending e-mails with both html and plain text versions of the body. This column specifies the html version of the body.

If this column is null it will be ignored.
Body_Plain optional string
Used when sending e-mails that contains both html and plain text versions of the body. This column specifies the plain text version. You can also set the 'alternative_plaintext' column to automatically generate a plain text version of your message.

If this column is null it will be ignored.
Cc optional string
The 'cc' property in the email, if it contains more than 1 address then the addresses need to be separated with ';'.
Only addresses containing standard 7-bit ASCII-characters are supported (thus the characters åäö are not supported).
Css optional string
The stylesheet for the html message. Use one of the Softadmin stylesheets by calling SoftadminApi.Css_StyleSheet(@CssId).

The contents of this column will be inserted in the <head> section of the html document.
DocType optional string
Meta data preceeding the actual html document, e.g. <!DOCTYPE>. Only present in html messages.
EmailId mandatory string
Unique identifier for this email. You may never try to send the same email more than once during a single execution of batchemail.aspx, even if the first attempt to send the mail failed.
From mandatory string
The 'from' property in the email.
Only addresses containing standard 7-bit ASCII-characters are supported (thus the characters åäö are not supported).
From_Name optional string
Assigns a human-friendly display name for the from address.
Html optional bit
1 sets the 'bodyformat' property to html, 0 sets it to text. Default is 1.
IsHighPriority optional bit
Flags the message as high priority/urgent.
Not all mail clients will respect this - Gmail, most notably, does not.
ListUnsubscribe optional string
Used to set the List-Unsubscribe header to make it easier to unsubscribe from mail lists. See RFC 2369.

This will display unsubscribe links in email clients given the protocol is supported (mailto is most widely supported), and the sender is trusted which it usually isn't. Setting this header will not take away the legal obligation to also have an unsubscribe link in mass emails.

In reality this header is mostly used to improve SPAM rating, but regardless the unsubscribe mailto and/or link defined in the header still must be implemented.
ReplyTo optional string
The 'reply-to' property in the email.
Only addresses containing standard 7-bit ASCII-characters are supported (thus the characters åäö are not supported).
Subject mandatory string
The 'subject' property in the email.
To mandatory string
The 'to' property in the email, if it contains more than 1 address then the addresses need to be separated with ';'.
Only addresses containing standard 7-bit ASCII-characters are supported (thus the characters åäö are not supported).

Resultset: File attachments

Resultset with attached files.
Table count: repeated exactly once
Row count: zero or more rows
Columns
ContentId optional string
Content-ID to give attachment, which must be a valid content-ID as defined in RFC 2111. Used to inline attachments in email body.
ContentType optional string
MimeType to use for the attachment. If omitted then content type will be inferred from the filename (so for example "mypicture.png" will get "image/png" as content type).
xxx mandatory binary
Contains a file that should be attached, component uses the first found image-column in resultset. Must not be NULL.
xxxfilename mandatory string
Contains the filename of the attached file. The column name should be the same as the image column name followed by 'filename'.

Resultset: Menu item attachments

Resultset with attached menu items. You should only attach menu items with the Excel, RTF Document, PDF Document, or Zip Archive components.
Table count: repeated exactly once
Row count: zero or more rows
Columns
ContentId optional string
Content-ID to give attachment, which must be a valid content-id as defined in RFC 2111.
Filename mandatory string
Filename to give attached menu item.
MenuItem optional string
Alias of menu item to use as attachment.
MenuItemId optional int
Deprecated. Use MenuItem instead.

Menu item to use as attachment.
PassingFields optional string
Passing fields that will be appended to the link if the attachment is a menu item. (e.g. x=3&y=4).

SQL Call: E-mail sent (mandatory)

Statement that is executed after each e-mail to confirm that the email was sent (no resultset is expected), this database call is only executed if the column 'emailid' is returned in SQL (database call 2).

May modify database: Yes

Parameters

@emailid string
Contains the 'emailid'-column in SQL (database call 2) to confirm that this e-mail has been sent.

SQL Call: E-mail failed (mandatory)

Call made when an e-mail failed to be sent. This only indicates the sending SMTP server refused the mail, this does not ensure the e-mail could be delivered to the recipient.

May modify database: Yes

Parameters

@emailid string
ID returned from earlier SQL call
@errorcode int
Possible value Description
1 No recipients specified. No recipients were specified in any of the fields To, CC, BCC.
-1 Unknown error.
2 The mail message contains invalid data such as NULL in body column.
3 At least one attachment wasn't generated correctly.
@errormessage string
Information that might be useful in figuring out what went wrong.

SQL Call: Validate parameters

Allows you to validate the SQL parameters before any other SQL is run in the component. This call is only made if the SQL is a stored procedure and Validate parameters is checked.

May modify database: No

Parameters

@Force bit
Set to 1 if the last call to validate parameters used admin_force and the user clicked OK in the OK/Cancel dialog.
@ValidateParams bit
Set to 1 when this call is made.

Resultset: Messages (optional)

Table count: repeated zero or one time
Row count: zero or one row
Columns
ADMIN_Force optional string
Message asking the end user to confirm their parameters.
ADMIN_Message optional string
Message explaining why the parameters are rejected.

Custom access control and logging

SQL Call: Custom access control and logging

Use this call to restrict which entries a user is allowed to view and edit, and to log which entries a user views.

Access to a menu item is normally controlled through functions and roles alone but some entities need more fine grained control. For example, a user may have access to the View Member menu item for normal members but not for members with a protected identity.

The menu items a user visits are always logged (in ADMINLogMenuItem) but for sensitive data you may need to log exactly what entries are viewed. Do the logging in this call as the common ways of viewing data (grid and InfoSQL) are not allowed to modify the database.

If you bind a scalar function instead of a stored procedure to this call then its name must end with '_GrantAccess'.

May modify database: Yes

Resultset: Access permissions

Return whether the user is allowed to visit the menu item with the current parameters.
Table count: repeated exactly once
Row count: exactly one row
Columns
GrantAccess mandatory bit
1 if the user is allowed to view the menu item, 0 if the user should not be allowed to view the menu item.

If 0 then an error will be logged as the user should not have been able to reach the menu item with the given parameters in the first place.