It is very easy to send email with ASNA Visual RPG. The core enablers are baked into the .NET Framework in these two namespaces:
The documentation for the
System.Net.Mail.SmtpClientclass says that because this class "doesn’t support many modern protocols" it is deprecated and that you should use the Nuget MailKit package to send emails. However, the
System.Net.Mail.SmtpClienthas worked fine for me for a long time with the SMTP services I use. It appears to be obsolete only when used with Xamarin. Read more about this issue here.
The project needs an
App.config file that provides your SMTP server configuration details. An
App.config.sample file is included to use as a base for your tailored
- The name or IP address or your SMTP server
- The SMTP port (which is almost always 587)
- The SMTP user
- The SMTP user password
- The email "from" address
<?xml version="1.0" encoding="utf-8"?>
<add key="smtp-server" value="SMTP IP address or name/>
<add key="smtp-port" value="587"/>
Port 465 is deprecated and most SMTP servers require using
port 587 to send eamil with TLS.
<add key="smtp-user" value="smtp user"/>
<add key="smtp-password" value="smtp password"/>
<add key="from-address" value="email from address"/>
App.config.sample file to
App.config and fill in your SMTP provider details.
This project was compiled with AVR 15x. This project be opened and used with higher versions of AVR. You can’t open this project with an earlier version of AVR, but if you copy and pasted the code as-in to older versions I am pretty sure it works at least down to AVR 12.x.
Send an email
This repo provides a reusable
Emailer class that you can use to send emails through an SMTP server with ASNA Visual RPG. The project code on GitHub includes a more detailed example, but the short version of sending email with the
Emailer class looks like this:
DclFld em Type(Emailer) New()
em.Subject "This is the email subject"
em.Body = "This is the email body"
Emailer has been used successfully with several email providers including Office 365, GMail, and Zoho. If you use two-factor authentication with your SMTP provider, check its documentation. Generally, with two-factor authentication you’ll need to generate a special-case password.