How to send excel file to mail in as400

A classic AS/400 question!

To send an Excel file as an attachment via email from an AS/400 system, you'll need to follow these steps:

Prerequisites:

  1. You have an AS/400 system with an email client installed (e.g., IBM i Mail, Lotus Notes, or a third-party email client).
  2. You have an Excel file (.xlsx or .xls) that you want to send as an attachment.
  3. You have a valid email address and password for the recipient.

Step 1: Convert the Excel file to a format that can be sent via email

The AS/400 system uses a different file format than Excel, so you'll need to convert the Excel file to a format that can be sent via email. You can use the XLSTOAS400 command to convert the Excel file to a fixed-format file (e.g., .txt or .csv) that can be sent via email.

Example:

XLSTOAS400 FILE(*FILE) FROMFILE(MYEXCEL.XLS) TOFILE(MYEXCEL.TXT)

This command converts the MYEXCEL.XLS file to a MYEXCEL.TXT file in the current working directory.

Step 2: Create an email message

Use the MAIL command to create an email message with the converted file as an attachment.

Example:

MAIL TO([email protected]) FROM([email protected]) SUBJECT(My Excel File)
ATTACH(MYEXCEL.TXT)

This command creates an email message with the subject "My Excel File" and attaches the MYEXCEL.TXT file.

Step 3: Send the email

Use the MAIL command to send the email message.

Example:

MAIL SEND

This command sends the email message to the recipient.

Alternative method using a third-party email client

If you have a third-party email client installed on your AS/400 system, you can use its API or scripting capabilities to send the email message with the Excel file attachment.

For example, if you have IBM i Mail installed, you can use its API to send the email message:

CALL QSYS/QIBM/IIMAIL/MAIL SEND
  TO([email protected])
  FROM([email protected])
  SUBJECT(My Excel File)
  ATTACH(MYEXCEL.TXT)

This command sends the email message using the IBM i Mail API.

Remember to replace the placeholders (e.g., MYEXCEL.XLS, MYEXCEL.TXT, [email protected], [email protected]) with the actual file names and email addresses.