Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending an email using a SAS data step not executing

Status
Not open for further replies.

FatCaptain

Programmer
Jun 9, 2010
4
GB
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.
 

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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top