BookmarkSubscribeRSS Feed
Sathyaseelan_C
Fluorite | Level 6

I am using the below Json for posting the Mail using our SAS STUDIO from SAS VIYA 3.5 ENV,.

I am getting 200 Response and have received the mail. But not with the attachments. Kindly advise. 

data test;
file mail;
put '{' 
/'"to":' 
/'['
/'{'
/'"address": "sathyaseelan_chandramohan@example.com",'
/'"personal": "Example User"'
/'}'
/'],'
/'"from": {'
/'"address": "sathyaseelan_chandramohan@example.com"'
/'},'
/'"subject": "Subject goes here",'
/'"htmlMessage": "<html><b>Note:</b>This is an HTML email.</html>",'
/'"attachment": ['
/'{'
  /'"type": "application/x-zip",'
  /'"name": "Summary_SR_20240405_1334.zip",'
  /'"data": "/tmp/Summary_SR_20240405_1334.zip"'
/'}'
/']'
/'}'
run;
 
data _null_;
infile mail;
input;
put _infile_;
run;
 
filename resp clear;
filename resp temp;
 
 
options set=SSLREQCERT="allow";
/*Invoke create parent SR API*/
proc http
method="POST" 
out=resp
CLEAR_CACHE
in=mail;
debug level=2;
 
headers
"Authorization" = "Bearer &access_token"
"Content-type" = "application/vnd.sas.mail+json";
run;
 
%put &=SYS_PROCHTTP_STATUS_CODE;
4 REPLIES 4
Sathyaseelan_C
Fluorite | Level 6
Logs showing 200 Response and without any Errors. Also i have received the mail. But without the attachments.
Sajid01
Meteorite | Level 14

If it is the intention to send email with http post request and if you are open to looking at python, then please have a look at
https://stackoverflow.com/questions/58242068/i-want-to-send-file-as-attachment-to-an-api-post-reques...

gwootton
SAS Super FREQ
The "data" of the attachment array needs to be the actual contents of the file rather than a pointer to the file, PROC HTTP would not know to resolve that to the physical file and then properly encode it, it is sending to the mail service literally "/tmp/Summary_SR_20240405_1334.zip".

I think you'd need to base64 encode the file and put it in the "mail" file.
--
Greg Wootton | Principal Systems Technical Support Engineer