DATA Step, Macro, Functions and more

Sending e-mail from SAS

New Contributor
Posts: 4

Sending e-mail from SAS

I'm trying to have a SAS program send an e-mail.  We have SAS 9.3 running on Windows 7 professional but are still using Outlook 2007.  Has anyone done this successfully with a similar setup?


Posts: 72

Re: Sending e-mail from SAS

Have you had a chance to review previous postings regarding sending emails from SAS?

New Contributor
Posts: 4

Re: Sending e-mail from SAS


Thanks for the direction.  I looked at the threads you mentioned.  In the first one, she says she put in the ip address of her mail system in the emailhost parameter but when I do that it only looks at the first 7 characters and treats the rest as an 'unrecognized option'

Other than that,not getting anywhere.

Super Contributor
Posts: 282

Re: Sending e-mail from SAS


It might be worth posting your code with the error message showing, then it might help someone identify the issue.

One question is have you ever managed to send email via SAS with a different set up?



New Contributor
Posts: 4

Re: Sending e-mail from SAS

I have tried it with emailsys SMTP with the following result: 

5980 %let hst = EXCHANGE;


5982 options emailsys=SMTP;

5983 options emaildlg=NATIVE;

5984 options emailport=25;

5985 options emailauthprotocol=NONE;

5986 options emailhost=&hst;

5987 options NOEMAILFROM;

5988 options emailid="";

5989 options emailpw=XXXXXXXX;



5992 filename outbox email "" debug;


5994 data _null_;

5995 file outbox

5996 to=("")

5997 /* Overrides value in filename statement */

5998 cc=("")

5999 subject="My SAS Output"

6000 /* attach=("C:\sas\results.out" "C:\sas\")*/

6001 ;

6002 put 'Folks,';

6003 put 'program ran';

6004 put 'It worked great!';

6005 run;

NOTE: The file OUTBOX is:

E-Mail Access Device


ERROR: Email: The software caused the connection to abort.

NOTE: The SAS System stopped processing this step because of errors.

NOTE: DATA statement used (Total process time):

real time 2.16 seconds

cpu time 0.03 seconds

and with emailsys MAPI

as follows:


6006 %let hst = EXCHANGE;


6008 options emailsys=MAPI;

6009 options emaildlg=NATIVE;

6010 options emailport=25;

6011 options emailauthprotocol=NONE;

6012 options emailhost=&hst;

6013 options NOEMAILFROM;

6014 options emailid="";

6015 options emailpw=XXXXXXXX;



6018 filename outbox email "" debug;


6020 data _null_;

6021 file outbox

6022 to=("")

6023 /* Overrides value in filename statement */

6024 cc=("")

6025 subject="My SAS Output"

6026 /* attach=("C:\sas\results.out" "C:\sas\")*/

6027 ;

6028 put 'Folks,';

6029 put 'program ran';

6030 put 'It worked great!';

6031 run;

ERROR: Undetermined I/O failure.

NOTE: The SAS System stopped processing this step because of errors.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.01 seconds

Thanks again!

Respected Advisor
Posts: 3,892

Re: Sending e-mail from SAS

Before you define too many of the email options run...

proc options group=email;


...and check what's already defined for you.

In your code you call your email server just "EXCHANGE".

%let hst = EXCHANGE;

options emailhost=&hst;

Shouldn't this be a fully qualified name like (how is it called in the account settings of your Outlook client?).

"ERROR: Email: The software caused the connection to abort"

You get this error if some of your email settings are wrong (wrong server name, wrong port,...). port 25 is only the standard port. It can be different at your site.

Posts: 31

Re: Sending e-mail from SAS

In your code I see that you try to connect to GMAIL using the EMAILSYS=SMTP option. That does not work. GMAIL uses a secure link to connect to the mail server and that is not supported in the current release of the SMTP option. So you must use EMAILSYS=MAPI.

However it is important that the EMAILID is exactly (case sensitive) as it is defined in the mail client that handles the MAPI calls. In GMAIL the EMAILID is normally the mail address, without the domain information. E.g. I used the email address for communications regarding SAS Global Forum 2012 and the login code for GMAIL was erik.t.sasgf2012. So that should be the value in the EMAILID option.

Something similar applies when trying to send mails via Hotmail.

Ask a Question
Discussion stats
  • 6 replies
  • 5 in conversation