Monday, February 27, 2012

Configure email in AS/400

First of all, you have to understand that the AS/400 supported E-mail long before the Internet came around, and SMTP became popular. It used an e-mail system called SNADS that IBM developed specifically for their business machines.

That's why commands like SNDDST seem so complicated. They weren't designed for today's Internet e-mail, they were designed for SNADS and later adapted for SMTP.

Before explaining how to set up e-mail, I'm making the following assumptions:

  • Your system is already configured for TCP/IP.
  • You already have DNS lookups working from your iSeries to Internet domains as well as local domains.
  • You have an Internet Service Provider (ISP) who has given you an outgoing mail server to relay your e-mail. Or you have an internal SMTP server that your company uses for e-mail.


The first thing you'll want to do is configure your iSeries SMTP server. This is used when sending mail as well as receiving it. Type the following command:

CHGSMTPA AUTOSTART(*YES) MAILROUTER('your.isp.smtp.server') FIREWALL(*YES) ALWRLY(*BOTH)


  • AUTOSTART(*YES) tells the system you want this server to start automatically when TCP/IP is started.
  • the MAILROUTER keyword tells where the iSeries should send outgoing e-mail to. This'll be the internal SMTP server that your company uses for mail, or the one that your ISP provided you. (192.168.10.200)
  • The FIREWALL(*YES) keyword tells the iSeries to always send mail though the MAILROUTER, never try to deliver it directly.
  • ALWRLY(*BOTH) is used to configure who is allowed to send mail though this server. Do not set this to *ALL or spammers will be able to use your machine to send spam without your consent. With *BOTH, you'll have to use the ADDSMTPLE command to control which computers can use your SMTP server (more later).


You'll also want to make sure that e-mail messages are not split up, even if they're big. This has always seemed strange to me, but it's controlled by the CHGPOPA (Change POP3 Attributes) command.

CHGPOPA MSGSPLIT(*NOMAX)

As I mentioned above, you'll need to configure which IP addresses are allowed to send mail through your iSeries system. In this example, all the computers who can send mail have IP addresses that begin with 192.168.5, so I run the following command:

ADDSMTPLE TYPE(*ACCEPT) INTNETADR('192.168.5.0') SUBNETMASK('255.255.255.0')

You can run this command more than once if you need to add more than one subnet.

The next thing you'll need to do is set up a gateway that allows SNADS tools like SNDDST to send Internet e-mail. To do that, type the following commands:

ADDDIRE USRID(INTERNET GATEWAY) USRD(‘Internet SMTP gateway’) SYSNAME(INTERNET) PREFADR(NETUSRID *IBM ATCONTXT)


CHGDSTA SMTPRTE(INTERNET GATEWAY)

After running this command, the SNDDST command will use the gateway so that e-mail will be sent to the local SMTP server.


Now that SMTP is configured on your system, so go ahead and start the SMTP server

STRTCPSVR SERVER(*SMTP)

(If it was already running, use ENDTCPSVR to end it. Then use WRKACTJOB SBS(QSYSWRK) to make sure that all of the QTSMTPxxxx jobs end, then use STRTCPSVR to start it up again.)

Each user who needs to send e-mail using SNDDST will need to have a directory entry and SMTP e-mail address configured on the iSeries.

ADDDIRE USRID(BANKDUDE S10262BA) USRD('Bank Dude profile')

WRKNAMSMTP TBLTYPE(*SYSTEM)

  1. Use option 1=Add
  2. Type the same name/address that you used on the ADDDIRE command
  3. Enter the SMTP e-mail address for this user.


Once all of that is done, it should be easy to send off a test e-mail with SNDDST. For example:

SNDDST TYPE(*LMSG) TOINTNET(('bankdude@example.com')) DSTD('Put E-mail Subject Here') LONGMSG('Hi Dude. This is an E-mail message sent from my iSeries system.')

You should also be able to configure tools like Outlook, Firebird, Eudora, etc to send mail using your iSeries SMTP server. For user-written e-mail, that's nicer than using SNDDST. Though, SNDDST is still nice for automatic messages generated by programs.

There are also lots of free e-mail tools on the Web that can use this SMTP server. They provide many more capabilities than SNDDST does. But, alas, this message is getting too long, so I'll stop there.