Wednesday, July 9, 2014

Formatting the email body in SNDSMTPEMM

sndsmtpemm email body

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:

  1. Can I send an email with a message in the email’s body and without an attachment?
  2. 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:

               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')

                 SUBJECT('Alert: PO received') + 


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.


  1. Sivakumar Raju BhJuly 10, 2014 at 5:09 AM

    I am unable to use the command. I use V5R9.
    I am getting following message: Command SNDSMTPEMM in library *LIBL not found.

    Do we need to install any patches from IBM to access this.

    1. As I mentioned in my first post about this command, Email IFS files:

      "SNDSMTPEMM has been introduced, via PTF, to IBM i 6.1 and 7.1"

      If your sever is using V5 then this command will not be available to you.

  2. Simon, Wonderful tip. I enjoy your posts.
    1 question, the mail works internally, but not to outside domains. Any way to include those?

  3. I have not been able to get this is work. I get QSMTPUSR in library *libl type *PNLGRP not found. I understand we need to usr WRKNAMSMTP, I dont know if that is set up correctly.

    1. Are you at release 6.1 or greater?
      Do you have the requisite PTF loaded?
      Could it be an authority problem that the command is there & you are not authorized to it?

  4. You can get a 400 character Note by applying a PTF. It does work, but I can't find the PTF number at the moment

  5. To get SNDSMTPEMM note field to use up to 400 chars apply the following PTF. Can be applied either immediate or delayed.
    V6R1 5761TC1 SI51161
    V7R1 5770TC1 SI51160

  6. I have been using this command. It allows me to send email without attachment (without error message), but, it does not allow me to send email with attachment (the message is "Send E-mail Successful"). Any thoughts?

    1. You have not given any information about any error message you receive when you try to send an attachment. Without that it is hard to guess what might be your problem. Have you done what is described at the bottom of this post?

    2. can the body be more then 400 char?

    3. At present I believe the maximum is 400 characters. If needed any more than that then I would place the text in an attachment.

  7. I'm trying to use a variable in cl pgm to have multiple email address some are *PRI and some *CC for the RCP parm
    my value for field RCP is
    ( *PRI) ( *PRI) ( *CC)
    but when I use this in the
    command it puts single quotes around the value and it causing an invalid email address
    ( *PRI) ( *CC)'))

    any way around this besides creating an RPG pgm to build the whole command

    1. I have to admit I have never used a %TRIM in that field. If you need to trim could you not into another variable and use that in the command?

    2. You cannot use '( *PRI) ( *PRI) ( *CC)' as a variable value and then try to use the variable in a command. The command must see individual values for each subparameter. If you try to use a variable for all of the subparameters at the same time then the command uses the variable value for a single subparameter.

    3. Esto funciona:

      &MAIL |< ' ) ' || 'SUBJECT(' || &CHR |< +
      &SUBJ |< &CHR || ') ' || 'NOTE(' || &CHR +
      |< &NOTE |< &CHR || ') ' || 'ATTACH((' || +
      &CHR |< &RUTA |< &CHR |< ' *OCTET *TXT))')


    4. &CHR variable



To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.