BookmarkSubscribeRSS Feed
atul_desh
Quartz | Level 8

When I'm running below code in EG it is working fine [Abort Job and send error to mail id] but when same Program I'm running thru Unix SAS Grid it is not sending mail, Please help me out.. Thanks

 

Test_mail.sas : 


%macro errmail;
;run;quit;
%if %eval(&syserr > 4) %then
%do;
data _null_;
filename myfile email
to=("email_id@chk.com")
subject= "Subject Line_Test "

type="text/plain";

file myfile;
put 'Your job received the following ERROR/WARNING message:';
put;
put 'ERROR was:';
put "&syserrortext";
put;
put 'WARNING was:';
put "&syswarningtext";
run;
%abort cancel;
%end;
%mend errmail;

data ds1;
set ds2;
%errmail;

 

 

Below Command I'm using on Unix SAS Grid : 

 

 

sasgsub -gridwait -gridsubmitpgm test_mail.sas

 

Above command runs and abort the sas program which I want but not sending mail, as EG sending me the mail. 

 

 

 

 

14 REPLIES 14
atul_desh
Quartz | Level 8

Thanks Kurt for replying, I'm able to send mail thru Unix without aborting statement, how can I send mail with abort statement as it is working in EG. 

 

%macro errmail;
data _null_;
filename myfile email
to=("mail_id")
subject= "subject "

type="text/plain";

file myfile;
put 'Your job received the following ERROR/WARNING message:';
put;
put 'ERROR was:';
put "check2";
put;
put 'WARNING was:';
put "check1";
run;

%mend errmail;

%errmail;

Kurt_Bremser
Super User

I have the suspicion that your use of %abort cancel is the reason.

In batch mode, %abort cancel causes an immediate termination of the SAS job; since sending mail requires that SAS start an external command to hand the mail over to, the premature termination of SAS might cause this action to not be performed IMO.

(in workspace server mode, the SAS session is not terminated, only the submitted code)

Kurt_Bremser
Super User

Have you tried to explicitly close the file?

%macro errmail;
;run;quit;
%if %eval(&syserr > 4)
%then %do;

  filename myfile email
    to=("email_id@chk.com")
    subject= "Subject Line_Test "
    type="text/plain"
  ;

  data _null_;
  file myfile;
  put 'Your job received the following ERROR/WARNING message:';
  put;
  put 'ERROR was:';
  put "&syserrortext";
  put;
  put 'WARNING was:';
  put "&syswarningtext";
  run;

  filename myfile clear;

  data _null_;
  abort cancel;
  run;
%end;
%mend errmail;

data ds1;
set ds2;
%errmail;
atul_desh
Quartz | Level 8

Thanks but this also not working, when I'm running " only %errmail; then it is sending me mail from unix (after removing condition). but not sending me mail from unix when I put condition in it (&syserr).. In EG working fine. 

 

I don't know what is happening 😞

%errmail;

"

RW9
Diamond | Level 26 RW9
Diamond | Level 26

From the documentation:

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a002592796.htm

"You can send electronic mail programmatically from SAS using the SMTP (Simple Mail Transfer Protocol) e-mail interface. SMTP is available for all operating environments in which SAS runs. To send SMTP e-mail with SAS e-mail support, you must have an intranet or Internet connection that supports SMTP."

 

So I would say without any information that you are missing something on the Unix system.  Consult with your IT, perhaps its just a permission, perhaps they need to make something available.

atul_desh
Quartz | Level 8

Thanks RW9,

 

I'm able to send mail thru SAS Code from Unix but in this particular case I'm not getting mail, although that code is perfectly fine in SAS EG. 

ChrisHemedinger
Community Manager

Ensure that all EMAIL* options are set either in your program or in the autoexec for each grid session -- naming EMAILHOST, port, etc...

 

options emailhost='mailserver.company.com' emailsys=smtp;

 

It might be that when running in the grid, these aren't initialized and are resorting to the default settings.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
atul_desh
Quartz | Level 8

below macro is sending the mail from grid, but not the one I had issue and on EG it is working find. 

 

%macro errmail;
data _null_;
filename myfile email
to=("mailid")
subject= "test_subj "

type="text/plain";

file myfile;
put 'Your job received the following ERROR/WARNING message:';
put;
put 'ERROR was:';
put "check2";
put;
put 'WARNING was:';
put "check1";
run;

%mend errmail;

%errmail;

ChrisHemedinger
Community Manager

Run this code to check your e-mail options:

 

proc options group=email; run;

Check this within your EG environment and within your server/batch environment -- compare the results and see if you might need to explicitly set some of the EMAIL* options to make it work the way you need.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
atul_desh
Quartz | Level 8
Both are exactly same 😞


Batch O/p :

Group=EMAIL
EMAILACKWAIT=30 Specifies the number of seconds to wait for the SMTP server acknowledgement.
EMAILAUTHPROTOCOL=NONE
Specifies the SMTP e-mail authentication protocol.
2 The SAS System 09:54 Tuesday, November 28, 2017

NOEMAILFROM Does not require the FROM e-mail option when sending e-mail by using the FILE or FILENAME statements.
EMAILHOST=something.com (can't disclose)
Specifies one or more domain names for SMTP e-mail servers.
EMAILID= Specifies the SAS user's logon ID, profile or e-mail address.
EMAILPORT=25 Specifies the port number for the SMTP e-mail server that is specified in the EMAILHOST option.
EMAILPW=XXXXXXXX Specifies the password for the e-mail address specified by the EMAILID option.
EMAILUTCOFFSET= For SMTP e-mail sent using the FILENAME statement, specifies a UTC offset that is used in the Date header field
of the e-mail message.
EMAILSYS=SMTP Specifies the e-mail protocol that is used for sending electronic mail.


EG O/P :

Group=EMAIL
EMAILACKWAIT=30 Specifies the number of seconds to wait for the SMTP server acknowledgement.
EMAILAUTHPROTOCOL=NONE
Specifies the SMTP e-mail authentication protocol.
NOEMAILFROM Does not require the FROM e-mail option when sending e-mail by using the FILE or FILENAME statements.
EMAILHOST=something.com (can't disclose)
Specifies one or more domain names for SMTP e-mail servers.
EMAILID= Specifies the SAS user's logon ID, profile or e-mail address.
EMAILPORT=25 Specifies the port number for the SMTP e-mail server that is specified in the EMAILHOST option.
EMAILPW=XXXXXXXX Specifies the password for the e-mail address specified by the EMAILID option.
EMAILUTCOFFSET= For SMTP e-mail sent using the FILENAME statement, specifies a UTC offset that is used in the Date header field
of the e-mail message.
EMAILSYS=SMTP Specifies the e-mail protocol that is used for sending electronic mail.
nagaraj1991
Obsidian | Level 7

Did anyone know the solution for this?

G_Jin
SAS Employee

We had the same issue. Check your CFG file. 

We found our email settings were missing from the cfg file that the sas executable the batch job using. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 14 replies
  • 2982 views
  • 1 like
  • 6 in conversation