2 weeks ago - last edited 2 weeks ago
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 <email@example.com>' /* debug email list */ %end; from='Smith, John <firstname.lastname@example.org>' bcc=&bcclist sender='Smith, John <email@example.com>' reply='Smith, John <firstname.lastname@example.org>' 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.
2 weeks ago
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.