Hi! I'm trying to add logging function to an automated report that specifies whether an email was sent successfully. I'm currently using the filename...email method as shown below and the code works.
filename outbox email
%if &debug_flag = 0 %then %do;
to=&to_emails
%end;
%else %do;
to='Smith, John <someemail@myuniversity.edu>' /* debug email list */
%end;
from='Smith, John <someemail@myuniversity.edu>'
bcc=&bcclist
sender='Smith, John <someemail@myuniversity.edu>'
reply='Smith, John <someemail@myuniversity.edu>'
content_type="text/html"
%if &wrapup_exit_status = 0 %then %do;
attach=("&rptpath/&rptfn"
ENCODING='utf-8'
CONTENT_TYPE='application/pdf'
EXTENSION='pdf'
)
subject="Entrance Reports &deptnm MTC &rptwk"
;
ods html5 style=pearl body=outbox /* Mail it! */;
proc odstext;
p 'Hello, ';
p 'The highlight table at the front includes anyone that responded with information that could be important to know. The following items cause an employee to appear:';
list
item 'Marked any need in the special needs section';
item 'Have been a service member less than 3 years';
item 'Individuals older than 27';
item 'Indicated both struggling in training';
item 'Indicated both not having attended high school';
end;
%end;
%else %do;
subject="Entrance Reports &deptnm &rptwk"
;
ods html5 style=pearl body=outbox /* Mail it! */;
proc odstext;
p 'Hello, ';
p 'There are no individuals which have been flagged with special needs this week';
%end;
p 'Let me know if you have any questions';
run;
ods html5 close;
Usually for procedures I can simply check &syserr. However from what I gather when email information is sent to the email server the server simply accepts the request and doesn't send status codes (like if the email had an invalid address). Is there a way to work around this? I just need to know whether an email sent successfully, not specific details.
Thanks!
I believe you're dealing with an asynchronous process and the only thing you can get is the response that your request for sending an email was successful.
You would need to find a way to query the email server directly.
You can find quite a few non-SAS related discussions on the Internet around this topic. If any of these can give you a solution approach will depend on your level of access to the email server.
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.