Debugging errors with FILENAME Statement: EMAIL (SMTP) Access Methods and SMTP servers


This article covers how to debug errors with FILENAME Statement: EMAIL (SMTP) Access Methods and SMTP servers.

Table of Contents

Verifying SAS EMAIL Options

SAS EMAIL options specify the configuration to send email from SAS to an SMTP server. For information, see SAS Help Center: System Options That Control SMTP E-Mail.

To check these options and where they are set, run the following SAS code:

PROC OPTIONS GROUP=EMAIL VALUE; RUN

Debugging FILENAME EMAIL Access Method Errors

Most errors generated by the FILENAME EMAIL Access Method code are messages from the SMTP server. You can find details about these SMTP errors and possible resolutions by searching for the error message on the Web.

To see the standard SMTP communication between SAS (SMTP client) and the SMTP server, add the DEBUG parameter to the FILENAME EMAIL statement:

FILENAME MYEMAIL EMAIL ..... DEBUG;

DEBUG information is written to the SAS log:

Here is an example:


R: 250-STARTTLS
R: 250-AUTH LOGIN

If no additional information is provided by the DEBUG parameter, the SAS connection is not communicating with the SMTP server that is specified by SAS EMAIL options. Review the values set for the SAS EMAILHOST= and EMAILPORT= options.

Note: On Microsoft Windows, DEBUG information is not available when using the SAS option EMAILSYS=MAPI.

Sample Email Code 

Using a test SAS script overrides the current email server settings and can help with you figure out settings prior to committing them to a config file or to Metadata. Once the SAS test email script can send an email successfully, update the config file or Metadata to match the settings that worked. 

--------------------------

options emailsys=smtp;

options emailhost=("EMAIL_SERVER_SMTP_FQDN" STARTTLS);

options emailport=<25 or 465 or 587>;

options emailauthprotocol=NONE;

options emailid="PUT_SENDER_EMAIL_ADDRESS_HERE";

proc options group=email;

proc options option=config;

ODS _ALL_ CLOSE;

filename mailbox email DEBUG

to=('PUT_RECIPIENT_EMAIL_ADDRESS_HERE')

CC=('PUT_SENDER_EMAIL_ADDRESS_HERE')

type='text/html'

subject="Test Email #1";

ods html file=mailbox rs=none ;

OPTIONS MISSING=0;

PROC ODSTEXT;

P "Dear All,";

p " ";P "Hello World!" ;

RUN;

-------------------

Handling SSL or OpenSSL Errors for Secure SMTP Server Connections    

If SSL or OpenSSL errors occur during an SMTP server connection, enable SAS SSL enhanced logging. This logging captures behind-the-scenes TLS negotiations/details of a secure SMTP server connection. To enable enhanced logging, add the following before the FILENAME EMAIL code from a Foundation SAS® session (batch, DMS, or linemode):

%log4sas(); 
%log4sas_logger('App.tk.eam.ssl', 'level=trace');   
run;


<start existing FILENAME EMAIL SAS code>

Note: The %log4sas macros do NOT work on a Workspace Server or other SAS servers using the -LOGCONFIGLOC option. You must use a Foundation SAS session (SAS CLI, batch, DMS or linemode) for the logger to capture trace-level messages to a log file.

If you cannot replicate the FILENAME EMAIL SSL error from a Foundation SAS session, obtain SSL/TLS details using the -LOGCONFIGLOC option and edit the logconfig.trace.xml file by adding the config above.

Before making changes, work with SAS Technical Support. This step creates additional information written to system logs, which is visible to all users.