DATA Step, Macro, Functions and more

sending emails from sas

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

sending emails from sas

 

 

options emailsys = smtp 
emailauthprotocol= login
EMAILACKWAIT=30
emailid = 'runnerupwang@outlook.com'
emailpw = 'XXXXXX'
emailhost = 'smtp.live.com' 
emailport = 25 ;
filename f_email email 
to =   '1055103120@qq.com'
from = 'runnerupwang@outlook.com'
subject = 'Automatic Email Sending Test'
;
data _null_;
file f_email;
put 'This is a test email with an RTF attachment via SAS programming.';
run;

I'm trying to send the email in the SAS9.4 with outlook mail, but failed, and I got an error message below, it seems that I should specify SSL, but I don't know how. Thanks for your info

 

ERROR: Login Failed
ERROR: Email: 530 5.7.0 Must issue a STARTTLS command first

 

PS: This code works if I changed the sender to 163 mail, and emaihost to smtp.163.com


Accepted Solutions
Solution
‎01-31-2016 08:10 PM
SAS Employee
Posts: 4

Re: sending emails from sas

I suggest you also take a look at the following

Usage Note 53215: How to set up your SAS® installation to use Secure SMTP via Gmail at:

http://support.sas.com/kb/53/215.html

More information on the options= emailhost option for SAS V9.4 can be found here:

http://support.sas.com/documentation/cdl/en/lesysoptsref/68023/HTML/default/viewer.htm#p1v9dr6zep9p9...

Here is some sample code:

options emailsys = smtp
emailid = 'runnerupwang@outlook.com'
emailpw = 'XXXXXX'
emailhost = 'smtp.live.com'
emailport = 25 ;

options emailhost=
(
"smtp.live.com"
STARTTLS auth=LOGIN
/* your Outlook address */
id=" runnerupwang@outlook.com
/* optional: encode PW with PROC PWENCODE */
pw="XXXXX" port=587
)
;
filename f_email email
to = '1055103120@qq.com'
from = 'runnerupwang@outlook.com'
subject = 'Automatic Email Sending Test';

data _null_;
file f_email;
put 'This is a test email with an RTF attachment via SAS programming.';
run;


View solution in original post


All Replies
Super User
Posts: 6,939

Re: sending emails from sas

This:

http://blogs.sas.com/content/sasdummy/2013/07/31/gmail-from-sas-program/

may point you in the right direction.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Solution
‎01-31-2016 08:10 PM
SAS Employee
Posts: 4

Re: sending emails from sas

I suggest you also take a look at the following

Usage Note 53215: How to set up your SAS® installation to use Secure SMTP via Gmail at:

http://support.sas.com/kb/53/215.html

More information on the options= emailhost option for SAS V9.4 can be found here:

http://support.sas.com/documentation/cdl/en/lesysoptsref/68023/HTML/default/viewer.htm#p1v9dr6zep9p9...

Here is some sample code:

options emailsys = smtp
emailid = 'runnerupwang@outlook.com'
emailpw = 'XXXXXX'
emailhost = 'smtp.live.com'
emailport = 25 ;

options emailhost=
(
"smtp.live.com"
STARTTLS auth=LOGIN
/* your Outlook address */
id=" runnerupwang@outlook.com
/* optional: encode PW with PROC PWENCODE */
pw="XXXXX" port=587
)
;
filename f_email email
to = '1055103120@qq.com'
from = 'runnerupwang@outlook.com'
subject = 'Automatic Email Sending Test';

data _null_;
file f_email;
put 'This is a test email with an RTF attachment via SAS programming.';
run;


Contributor
Posts: 27

Re: sending emails from sas

Thanks for your support. The final solution for sending the email with Outlook Account is similar to your sample code. I have setup the emailhost option in the second part option, I wonder why I have to setup the first part system options. 

 

 

/*First part Option Setup*/
options emailsys = smtp emailauthprotocol= login EMAILACKWAIT=30 emailid = '******@outlook.com' emailpw = 'XXXXXX' emailhost = 'smtp-mail.outlook.com' emailport = 25 ;
/*Second part Option Setup*/ options emailhost= ( 'smtp-mail.outlook.com' port=587 STARTTLS auth=login id='******@outlook.com' /* optional: encode PW with PROC PWENCODE */ pw='XXXXXX' ) ; filename f_email email to = ('OutMail_Address1' 'OutMail_Address2') subject = 'Automatic Email Sending Test' attach = 'C:\Users\Think\Desktop\test.rtf' ; data _null_; file f_email; put 'This is a test email with an RTF attachment via SAS programming.'; run; filename f_email clear;

 

SAS Employee
Posts: 4

Re: sending emails from sas

The difference between these two is that SMTP over SSL first establishes a secure SSL/TLS connection and conducts SMTP over that connection, and SMTP with STARTTLS starts with unencrypted SMTP and then switches to SSL/TLS. This is why the email STMP system options in the SAS code are specified first, and the email host options STARTTLS are specified second.

Check this post out if you require further information:

http://stackoverflow.com/questions/17281669/using-smtp-gmail-and-starttls
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 1183 views
  • 2 likes
  • 3 in conversation