SEND_EMAIL scalar function
The SEND_EMAIL scalar function sends an email to a one or more recipients. This is done by using the SNDSMTPEMM (Send SMTP E-mail Message) CL command.
This function assumes that the user invoking this function has been registered to the SMTP server by using the ADDUSRSMTP (Add User SMTP) CL command. If the SMTP server is not active, this function will attempt to start it before sending the email.
Authorization: See Note below.
- to-email
- A character string containing one or more email addresses. Addresses must be separated by a comma. Blanks included before or after each comma are ignored.
- subject
- A character string up to 255 characters long containing the subject of the email.
- body
- A character string up to 5000 characters long containing the body of the email.
- attachment
- A character string containing up to 10 path names of integrated file system files to be sent as attachments to the email. Each absolute path name can be up to 200 characters long. Path names must be separated by a comma. Blanks included before or after each comma are ignored.
- cc-email
- A character string containing one or more email addresses to be included in the carbon copy list. Addresses must be separated by a comma. Blanks included before or after each comma are ignored.
- bcc-email
- A character string containing one or more email addresses to be included in the blind carbon copy list. Addresses must be separated by a comma. Blanks included before or after each comma are ignored.
Note
This function is provided in the SYSTOOLS schema as an example of how send an email using the SNDSMTPEMM CL command in an SQL scalar function. Similar to other Db2® for i provided tools within SYSTOOLS, the SQL source can be extracted and used as a model for building similar helper functions, or to create a customized version within a user-specified schema.
Services provided in SYSTOOLS have authorization requirements that are determined by the interfaces used to implement the service. To understand the authority requirements, extract the SQL for the service and examine the implementation.
Examples
- Send an email to a user with an
attachment.
VALUES SYSTOOLS.SEND_EMAIL(TO_EMAIL => 'someuser@gmail.com', SUBJECT => 'Status for last week', BODY => 'Attached is the status information for last week.', ATTACHMENT => '/home/myuser/status.log');
- Send an email to multiple users with 2
attachments.
VALUES SYSTOOLS.SEND_EMAIL(TO_EMAIL => 'someuser@gmail.com, mymanager@xyz.com', CC_EMAIL => 'anotheruser@gmail.com', SUBJECT => 'Status and future plans', BODY => 'Attached is the status for last week and the future plan.', ATTACHMENT => '/home/myuser/status.log, /home/myuser/plan.docx');