Error Handling With Sending Emails (Checking whether an email sent successfully)

Reply
Occasional Contributor
Posts: 15

Error Handling With Sending Emails (Checking whether an email sent successfully)

[ Edited ]

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!

Respected Advisor
Posts: 4,743

Re: Error Handling With Sending Emails (Checking whether an email sent successfully)

@yus03590

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.

Ask a Question
Discussion stats
  • 1 reply
  • 69 views
  • 0 likes
  • 2 in conversation