This tutorial explains how to send emails with attachments via SAS.
Send Emails with Attachments and cc Options
If Error sending XLSX files
"Excel found unreadable content in "temp.xlsx". Do you want to recover the contents of this workbook? If you trust the source of this workbook, click yes. Excel cannot open the file "temp.xlsx" because the file format or the file extension is not valid. Verify that the file has not been corrupted and the the file extension matches the format of the file."
Solution : Use content_type option in the attach statement.
Send Emails with Attachments and cc Options
data _null_;Note : You can also add BCC option. For eg. bcc="abc@site.com"
file sendit email
from="abc@provider.com"
to=("xyz@provider.com")
cc=("uvxyz@provider.com"
"pqrs@provider.com")
subject="Important Document"
importance="High"
attach=("C:\xxxx\Proc_logistic.xls");
put "Please find attached the file";
put;
put "Thanks!";
run;
If Error sending XLSX files
"Excel found unreadable content in "temp.xlsx". Do you want to recover the contents of this workbook? If you trust the source of this workbook, click yes. Excel cannot open the file "temp.xlsx" because the file format or the file extension is not valid. Verify that the file has not been corrupted and the the file extension matches the format of the file."
Solution : Use content_type option in the attach statement.
attach=("C:\xxxx\Proc_logistic.xlsx"content_type="application/xlsx")List of Content_type options with file extensions
Extension | Content_type |
---|---|
bmp | image/bmp |
csv | application/vnd.ms-excel |
doc | application/msword |
exe | application/octet-stream |
gif | image/gif |
htm | application/html |
html | applicaton/html |
jpeg | image/jpeg |
jpg | image/jpeg |
log | text/plain |
application/pdf | |
png | image/png |
ppt | application/vnd.ms-powerpoint |
sas7bdat | application/sas |
tar | application/x-tar |
text | text/plain |
txt | text/plain |
xls | application/excel |
xlsx | application/xlsx |
zip | application/x-zip-compressed |
Send Multiple Attachments
data _null_;
file sendit email
from="abc@provider.com"
to=("xyz@provider.com")
cc=("uvxyz@provider.com"
"pqrs@provider.com")
subject="Important Document"
importance="High"
attach=("C:\Deepanshu\Proc_logistic.xlsx" content_type="application/xlsx"
"C:\Deepanshu\Summary.pdf" content_type="application/pdf"
"C:\Deepanshu\Summary.doc" content_type="application/word");
put "Please find attached the file";
put;
put "Thanks!";
put;
run;