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.
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
emailauthprotocol=plain
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.
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.
@ChrisHemedinger
Can you please let me know what information I should request from the person in charge of the SMTP server?
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.
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.
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.
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?
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.
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.
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?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.