DATA Step, Macro, Functions and more

Create an email but do not send it directly

Reply
Frequent Contributor
Posts: 127

Create an email but do not send it directly

Hi all,

Would anyone of you know whether this is possible to generate an email (to:, cc:, header, content and attachment) but without sending it directly (under windows) ?

The purpose would be to save this email in a directory so that the Business might send it after validation of the attachment.

I've checked multiple white papers on the internet but unfortunately without finding anything interesting.

Thanks upfront for the help.

Regards,

Florent

Trusted Advisor
Posts: 2,115

Create an email but do not send it directly

Florent,

I'm not sure that you can do that as an e-mail is not a file.

My approach has been to send the e-mail from SAS to an "intermediary" e-mail address where it is checked and forwarded it as appropriate.  It adds a little garbage to the header, but accomplishes the goal.

Doc Muhlbaier

Duke

SAS Employee
Posts: 104

Create an email but do not send it directly

You can create an email without immediately sending it - details in the YouTube video SAS Programming Tip: Write an Email in SAS and Delay Sending  You'd have to somehow automate the "Save as Draft" in Outlook, though.

Regards,

SASJedi

Frequent Contributor
Posts: 127

Re: Create an email but do not send it directly

All,

I did accomplish the goal of my request by:

  • generating a VB script with SAS
  • having the VB script executed via a DOS command launched from SAS

For those who are interested, I could share a sample of the SAS program that I have created.

Regards,

Florent

P.S: What is the trick to use in order to copy/paste a SAS program into a post ? Each time I do it, I loose a lot of code...

Trusted Advisor
Posts: 2,115

Create an email but do not send it directly

To your PS:, just click "use advanced editor" in the top right corner of the message screen.

Frequent Contributor
Posts: 127

Re: Create an email but do not send it directly

I've tried but it still looses some lines of my code... It also breaks some lines of code into multiple lines in my post  :smileyconfused:

Isn't it possible to use an html tag in order to quote the code ? I saw a lot of correctly formatted code on the old SAS discussion forum.

Thanks!

Respected Advisor
Posts: 3,799

Create an email but do not send it directly

Florent wrote:

I've tried but it still looses some lines of my code... It also breaks some lines of code into multiple lines in my post 

Isn't it possible to use an html tag in order to quote the code ? I saw a lot of correctly formatted code on the old SAS discussion forum.

Thanks!


The only way I have found so far is to paste the code to MS Word and then to here.  It also preserves the syntax coloring.  I would like a more direct way too.

proc summary data=temp nway;

   class id datetime;

   format datetime datetime14.;

   output out=sum1;

   run;

Frequent Contributor
Posts: 127

Create an email but do not send it directly

Thanks!

So, here is the sample program that I used to save an email as a .msg file:

data _null_;

      currentDate= compress(put(today(), yymmdd10.), '-');

      currentTime= compress(put(time(), time8.), ':');

      call symput('timespan', compress(currentDate || currentTime));

run;

filename vbs "C:\WINDOWS\Temp\SaveEmail_&timespan..vbs" lrecl=256;

data _NULL_;

      file vbs;

      put 'Set objOutlook = CreateObject("Outlook.Application")';

      put 'Set objMailMessage = objOutlook.CreateItem(0)';

      put 'With objMailMessage';

      put '.To = "&sysuserid."';

      put '.Subject = "Test Email"';

      put '.Body = "Hello," & Chr(10) & Chr(10) & _';

      put '"This is a test email." & Chr(10) & Chr(13) & _';

      put '"The purpose of this email is to test that it was correctly saved on your desktop."';

      put ".SaveAs ""C:\Documents and Settings\&Sysuserid.\Desktop\Test_Email_&timespan..msg""";

      put 'End With';

run;

options noxwait xsync;

X "WScript //NoLogo //B C:\WINDOWS\Temp\SaveEmail_&timespan..vbs";

filename ERASEIT pipe "del ""C:\WINDOWS\Temp\SaveEmail_&timespan..vbs""";

data _NULL_;

      infile ERASEIT;

run;

Ask a Question
Discussion stats
  • 7 replies
  • 698 views
  • 1 like
  • 4 in conversation