In December, 2013, I wrote a post about using the SNDSMTPEMM command to send emails from the IBM i, Email IFS files. It has become the most popular post on this blog, and the one that has generated the most interest.
Two of the most commonly asked questions has been:
- Can I send an email with a message in the email’s body and without an attachment?
- Can I format the text in the email’s body so it is not just plain text?
Can I send an email with a message in the email’s body and without an attachment?
Yes. You can send an email without an attachment. Just put the text you want to be in the email’s body in the NOTE field of the command, for example:
SNDSMTPEMM RCP((firstname.lastname@example.org)) + SUBJECT('Alert: Purchase Order EDI') + NOTE('A purchase order has been received via + EDI and processed')
Or if we want to make it a bit more complicated/useful:
01 PGM PARM(&EMAIL &PONBR) 02 DCL VAR(&EMAIL) TYPE(*CHAR) LEN(30) 03 DCL VAR(&PONBR) TYPE(*CHAR) LEN(10) 04 DCL VAR(&NOTE) TYPE(*CHAR) LEN(200) 05 CHGVAR VAR(&NOTE) + VALUE('Purchase order ' || &PONBR |< + ' has been received, via + EDI, & processed') 06 SNDSMTPEMM RCP((&EMAIL)) + SUBJECT('Alert: PO received') + NOTE(&NOTE) 07 ENDPGM
If you are sending an attachment you do not need to have text in the NOTE field, but you do when there is no attachment, as in the above examples.
Warning: The documentation for this command states that "Up to 400 characters can be specified" in the NOTE field, but in my experience only the first 200 characters are sent.
Can I format the text in the email’s body so it is not just plain text?
I agree with the people who have asked me this question, the default format for the text in the NOTE field is pretty boring. It would make the email more appealing to the recipient if text in the body could be formatted. I can achieve this by using the CONTENT field in the command. The default value is *PLAIN, if I change the value to *HTML I can now use HTML to format the text. For example:
05 CHGVAR VAR(&NOTE) + VALUE('<font face="Arial"><h2><font + color="red">Hello world</font></h2> + This is an example of using <i>HTML</i> + in the <b>body</b> of the email.</font>') 06 SNDSMTPEMM RCP((&EMAIL)) SUBJECT('Test email') + NOTE(&NOTE) CONTENT(*HTML)
Alas with 200 characters there is not much you can say in the body of the email. But I can be use it to describe what an attachment is, or the parameters used to generate the data in the attached file.
You can learn more about the SNDSMTPEMM command from IBM’s command instructions here.