×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Sending an email using a SAS data step not executing

Sending an email using a SAS data step not executing

Sending an email using a SAS data step not executing

(OP)
Hi,

I'm trying to get SAS to send an email using a data step.

The code I am running is;

FILENAME emtest EMAIL 'me@mycompany' ;

DATA _null_ ;
FILE emtest
SUBJECT= 'SAS Test email' ;
PUT 'Hello,' ;
PUT ' ' ;
PUT 'This is a test email generated using a SAS data step.' ;
RUN ;


This code puts the focus on Lotus Notes (our email program), opens a new email, correctly populates the subject and body of the email but doesn't send it.

I can send the email by clicking on the Send button and recieve the test email without any problems.

What am I required to do to get this mail sent?

Thanks in advance for any help.

Regards,

FatCaptain.

RE: Sending an email using a SAS data step not executing


I had a situation about 2 years where I needed SAS to auto email without needing to click the Send button.  The way I got it done was by having SAS write a vbs file and then have SAS execute the vbs file.


CODE


/*** Create vbs code ***/
data _null_;
  file "c:\temp\AutoEmail.vbs";
put 'Set fso = CreateObject("Scripting.FileSystemObject")';
put 'Set theFile=fso.CreateTextFile ("C:\temp\Email_body.htm", vbTrue)';
put 'theFile.WriteLine "<HTML>"';
put 'theFile.WriteLine "<BODY>"';
put 'theFile.WriteLine "Example email with attachment.<br>"';
put 'theFile.WriteLine "</BODY>"';
put 'theFile.WriteLine "</HTML>"';
put 'theFile.Close';
put 'Set EmailBody = fso.OpenTextFile("C:\temp\Email_body.htm",1)';
put 'MyHTML = EmailBody.ReadAll';
put 'EmailBody.Close';
*Send email, auto send scripts;
put 'Set WshShell = CreateObject("WScript.Shell")';
put 'Set App = CreateObject("Outlook.Application")';
put 'Set Mail = App.CreateItem(0)';
put 'Mail.display';
put 'Mail.To = "youremail@user.com"';
put 'Mail.Subject = "SAS Test email"';
put 'Mail.HTMLBody = MyHTML';
put 'Mail.Attachments.Add("c:\temp\ExAttachmt.txt")';
put 'WshShell.AppActivate Mail';
/*put 'WshShell.SendKeys ("%s")';*/  *Uncomment to autosend;
run;

/*Run vbs file */
    x '"c:\temp\AutoEmail.vbs"';

This worked pretty good for our application.  (MS Outlook on a Windows machine using PC SAS)

dblan
 

RE: Sending an email using a SAS data step not executing

(OP)
Thanks for this. I had no idea scripting and executing vbs was possible!

I've had to amend it to make it work for Louts Notes.

The amended code is here should anyone else have need of it.

CODE

/*** Create vbs code ***/
data _null_;
  file "c:\temp\AutoEmail.vbs";
put 'Set fso = CreateObject("Scripting.FileSystemObject")';
put 'Set theFile=fso.CreateTextFile ("C:\temp\Email_body.htm", vbTrue)';
put 'theFile.WriteLine "<HTML>"';
put 'theFile.WriteLine "<BODY>"';
put 'theFile.WriteLine "Example email with attachment.<br>"';
put 'theFile.WriteLine "</BODY>"';
put 'theFile.WriteLine "</HTML>"';
put 'theFile.Close';
put 'Set EmailBody = fso.OpenTextFile("C:\temp\Email_body.htm",1)';
put 'MyHTML = EmailBody.ReadAll';
put 'EmailBody.Close';
*Send email, auto send scripts;
put 'Set Session = CreateObject("Notes.NotesSession")' ;
put 'Set Database = Session.GETDATABASE("", "")' ;
put 'If  Database.IsOpen = False Then Database.OPENMAIL' ;
put 'Set Document = Database.CreateDocument ' ;
put 'With Document' ;
put '.Form = "Memo"' ;
put '.SendTo = "me@mycompany.com"';
put '.Subject = "SAS Test email"';
put '.Body = "This is the body of the email"' ;
put '.SaveMessageOnSend = True' ;
put 'End With' ;
put 'With Document' ;
put '.PostedDate = Now()' ;
put '.Send 0' ;
put 'End With' ;

run;

/*Run vbs file */
    x '"c:\temp\AutoEmail.vbs"';

Cheers,

Fat Captain

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close