BookmarkSubscribeRSS Feed
Mahis
Quartz | Level 8

Hello SAS community,

 

I am attempting to send an email from a SAS program for the first time using the following method:

 

options emailsys=smtp 
        emailhost=smtphost.domainx.com 
        emailport=465
        EMAILID="email@domainx.com"
        EMAILPW="password";

filename mymail 
   email "recipient@domainy.com" 
   subject="Test Message";

data _null_;
   file mymail;
   put 'Hello there';
run;

But, I encountered this error:

"ERROR: Email: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM."

I would like to know if there is something I need to add or modify in order to resolve this issue.

13 REPLIES 13
yabwon
Onyx | Level 15

1)  emailauthprotocol= ?

2) is 

EMAILID="email@domainx.com"

valid email address ?

[EDIT:]

3) maybe:

emailhost=(smtphost.domainx.com SSL)

if you have SSL there?

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Mahis
Quartz | Level 8

@yabwon @SASJedi 

When I tried to add the following line to the options:

 

emailauthprotocol=Login

 

I got a different error message:

 

ERROR: Login failure
ERROR: Email: 504 5.7.4 Unrecognized authentication type

 

Does this indicate that my login credentials are invalid?

yabwon
Onyx | Level 15
emailauthprotocol=plain
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SASJedi
SAS Super FREQ

SMTP Error 530 is an authentication issue. The most likely cause is that you provided invalid login credentials. I tried your code using my own SMTP server and credentials, and it ran without error.

Check out my Jedi SAS Tricks for SAS Users
ChrisHemedinger
Community Manager

This might depend on your email server setup and authentication. If you have single-signon or two-factor authentication (common in cloud-based email), then a simple password might not be enough to authenticate. See tips here (specific to Gmail) and see if you need to adapt accordingly.

SAS Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.
Mahis
Quartz | Level 8

@ChrisHemedinger 

Can you please let me know what information I should request from the person in charge of the SMTP server?

ChrisHemedinger
Community Manager

Actually, in reviewing the original error I think you should try adding the FROM= option to your code. See How to send email using SAS for simple examples.

SAS Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.
Mahis
Quartz | Level 8

I tried the examples provided in the article, but I consistently encountered the same errors. but, when I tested sending a test email using the following command on the SAS compute server:

 

[sas@computeserver ~]$ swaks --to recipient@domainy.com --from email@domainx.com --server smtphost.domainx.com --tls --auth LOGIN --port 465

 

the email was successfully sent. I used the same credentials that I had previously used in the SAS program. I'm unsure what might be missing in the SAS program that prevented the email from being sent.

Tom
Super User Tom
Super User

Did you fix your SAS code to specify the FROM address?

Are you sure your SAS session is running on the same machine as your test?  Using the same userid?

 

Also do any of the addresses contain special characters that might make generating them from SAS tricky?

 

Does your SAS session have XCMD option enabled?  If so you could generate the email message first and then just call that same swaks command to send it.

 

Mahis
Quartz | Level 8

Did you fix your SAS code to specify the FROM address? Yes, but it didn't work.

 

Are you sure your SAS session is running on the same machine as your test? Yes, it is the same.

 

Also do any of the addresses contain special characters that might make generating them from SAS tricky? Yes, the FROM address is like this: username_ab@domainx.com .

 

you could generate the email message first and then just call that same swaks command to send it.

Could you please provide an example of how I can do that?

Tom
Super User Tom
Super User

Here a line from a 25 year old program:

*----------------------------------------------------------------------;
* When not in drug project environment, send email to SPE admin.       ;
*----------------------------------------------------------------------;
  %let status = PENDING;
  %let s_msg = Project &drug_c waiting for SPE set up;
  x cat %gdir(gsys)scs_msg1.txt | mailx -s "SCS request &drug_c setup"
   -c &email -r cdoadm@pfizer.com &speadm;

So the message to be sent was already written to the text file scs_msg1.txt.  Then the mailx command is called to send the message as an email.

Sajid01
Meteorite | Level 14

Hello @Mahis 
Please modify the following section of your code

filename mymail 
   email "recipient@domainy.com" 
   subject="Test Message";

to

filename mymail 
   to="recipient@domainy.com" 
   subject="Test Message";

It should work.

Mahis
Quartz | Level 8

Hello everyone, thank you all for your help. I was able to send an email using Tom's method of xcmd by adding the 'swaks' command in the script. However, I found that when I entered the password directly in the command, I got unsuccessful authentication because the password is decoded in base64 into a different password than what I typed. To avoid this issue, I used the following command to enter the password in this format:

 

$(echo 'cGFzc3dvcmR4' | base64 --decode)

 

This is the full command I used to send the email:

 

x "swaks --to &rec --from &sen --server &serv --tls --auth LOGIN --port 465 --auth-user userx1 --auth-password $(echo 'cGFzc3dvcmR4' | base64 --decode) --h-Subject &subj --body &email_body --attach &attachment";

 

Is it possible that SAS also decoded my password into another password, which led to unsuccessful authentication?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 2520 views
  • 11 likes
  • 6 in conversation