|
Hi!
I have writen this datastep that can send emails.
The reason that I won't use the "standard" email device, is that it
seems to often make problems, especially in batch. In addition this
program is stand-alone, it does not need a email client installed.
Would you like to test it in your environment?
To get it to work, you should make three changes:
The fileref SMTP should point to your mailserver (25 is probably the
right port)
The fileref ATC should point to an existing text file.
The TO macrovariable should contain a real emailaddress (that will
receive the mail).
I can't get it to work with binary attachments, anyone got a clue?
Stig
/* Sending a mail, attaching the textfile with the fileref "atc"*/
filename smtp socket 'mail.server:25';*the address of the SMTP
complaiant mail server;
filename atc "d:\temp\test.sas";*The ASCII file you are going to
attach;
%macro delay(sec);*A macro to prevent things from going too fast;
a=datetime();do while(datetime()-a<&sec);end;
%mend;
%let from=bill.gates@microsoft.com;*This address will be used as "From
address";
%let to=name@site.com;*This is the address of the recipient;
%let subject=The Results from the test;*The subject field of the mail;
%let body=Hi! The test works like a charm.;*Some text to put in the
body;
%let filename=the_program.sas;*What the attached ASCII file is named
in the mail;
data _null_;;
infile atc end = slutt;
file smtp;
%delay(0.5)
put 'ehlo localhost' '0D'x;
%delay(0.5)
put "mail from: &from" '0D'x;
%delay(0.5)
put "rcpt to: &to" '0D'x;
%delay(0.5)
put 'data' '0D'x;
%delay(0.5)
put 'Mime-Version: 1.0' '0D'x;
put 'Content-Type: multipart/mixed;
boundary="============_-1366791890==_============"' '0D'x;
put "To: &to" '0D'x;
put "From: &from" '0D'x;
put "Subject: &subject" '0D'x;
put '0D'x;
put '--============_-1366791890==_============' '0D'x;
put 'Content-Type: text/plain;' '0D'x;
put "Content-Disposition: inline" '0D'x;
put '0D'x;
put "&body" '0D'x;
put '--============_-1366791890==_============' '0D'x;
put 'Content-Type: text/plain;' '0D'x;
put "Content-Disposition: attachment; filename=""&filename""" '0D'x;
put '0D'x;
do until(slutt);*Putting out the attachment as ASCII;
input;
put _infile_;
end;
put '--============_-1366791890==_============--' '0D'x;
put '.' '0D'x;
put '0D'x;
%delay(0.5)
put 'quit' '0D'x;
stop;
run;
filename smtp;
filename atc;
*Keywords: socket smtp rfc 821 822 email batch attachments;
|