Hi
When i use the below code to attach a file into a mail body and send , the mail attached excel cannot be open , says its corrupted. i use a %MACRO sendMail(error=); to send the mail via SAS
%let attach ='/xxxdata/xxxx/xxxxr/xxx/xxx/xxx/abc_qa.xlsx' (content_type="application/xlsx");
I'm afraid you will need to share a lot more detail. Such a possibly the entire code for that macro and how you create the Excel file.
Did you attempt to verify that the file was readable before you attached it to the email?
One very likely scenario that causes this error is that however you create the xlsx file still is connected to the file so it is 'locked' and could not actually be attached.
Hope this helps
PROC EXPORT DATA= CPD_PD
OUTFILE= "/xxx/xxx/user/xxx/xxxx/xxxx/CPD_PD"
DBMS=xlsx REPLACE;
SHEET=xoxoxo;
RUN;
%MACRO sendMail(error=);
%LET tolist='vidia@.com'
%LET cclist='harin.jay@com';
%LET sender=sassrv;
%LET subject=Due dates;
%let attach ='/sasdata/xxx/user/xxxx/xxxxL/xxxxxx/CPD_PD.xlsx' (content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
PROC SQL NOPRINT;
create table myemail (c varchar(228));
insert into myemail values ("Dear All,");
insert into myemail values ("");
insert into myemail values ("The dates of the future ");
insert into myemail values ("");
insert into myemail values ("");
insert into myemail values ("Best Regards,");
insert into myemail values (" Team");
insert into myemail values ("");
insert into myemail values ("");
insert into myemail values ("");
insert into myemail values ("************ ************");
QUIT;
%PUT NOTE: &tolist;
%PUT NOTE: &cclist;
%PUT NOTE: &sender;
%PUT NOTE: &subject;
%PUT NOTE: &attach;
FILENAME tmpcode TEMP;
DATA _NULL_;
FILE tmpcode MOD;
PUT '%ccrSendEmail(SenderID=';
PUT "&sender,";
PUT "To=&tolist,";
PUT "CC=&cclist,";
PUT "attach=&attach,";
PUT "Subject='&subject');";
RUN;
%INC tmpcode;
%PUT NOTE: email sent;
%MEND sendMail;
%MACRO Main();
%sendmail();
%MEND Main;
%Main();
%put job end execution at %sysfunc(time(),timeampm.) on %sysfunc(date(),worddate.);
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.