Previously I've described how you can use SAS Enterprise Guide to send an e-mail message using Gmail as your e-mail provider.
In the article, I mentioned that you can also write SAS programs that send e-mail messages, but at the time you could not reach Gmail using the FILENAME EMAIL method. SAS did not support the security protocols (SSL) that are necessary to use the Gmail SMTP servers.
Beginning with SAS 9.4, FILENAME EMAIL supports the SSL and STARTTLS options, which you can use SAS to communicate directly with providers such as Gmail and Outlook.com.
Note that Google requires you to allow "Less secure apps" in order to send e-mail from a non-Google application. To remedy, you first have to enable Less secure apps from your Google account: security caveats apply. Then, you might have more success by using port 587 and the STARTTLS option (instead of port 485 and SSL, as my original example showed). If you use two-factor authentication on your Google account (a best practice), then you will need to take an additional step and create an "App password" -- which will allow a third-party app to use Gmail on your behalf and bypass the verification step. As always, your Google password and any App password you generate should be managed carefully and secured.
The following example program shows the options you would use for Gmail. Of course, you must specify your own Gmail address for the ID= value. And if you're squeamish about putting your plain-text password in a program, don't forget that you can use PROC PWENCODE to scramble it from prying eyes.
options emailhost= ( "smtp.gmail.com" /* alternate: port=487 SSL */ port=587 STARTTLS auth=plain /* your Gmail address */ id="firstname.lastname@example.org" /* optional: encode PW with PROC PWENCODE */ pw="your_password" ) ; filename myemail EMAIL to="email@example.com" subject="Read SAS blogs"; data _null_; file myemail; put "Dear Friend,"; put "I recommend that you read https://blogs.sas.com "; put "for lots of SAS news and tips."; run; filename myemail clear;
With SAS for Windows, this program should work without additional configuration. If you run SAS on UNIX or z/OS, you also need to specify the SSLCALISTLOC= system option, which tells SAS where to find the digital certificates that are needed for the SSL connection.