The TestEmail
class provides the SendEmail
method that you’ll copy into your code to send emails with the Emailer
class.
Using System
Using System.Collections.Generic
Using System.IO
Using System.Configuration
BegClass TestEmail
The SendEmail
method doesn’t know or care about
how the Email
class is sending email. If later you swap out System.Net.Mail's
email classes in the Email
class, the SendEmail
method continues to work.
Note that SendEmail is static (ie, Shared(*Yes)) and is therefore usable without instancing
its owner class.
BegSr SendEmail Access(*Public) Shared(*Yes)
DclFld em Type(Emailer) New()
Assign To and, optionally, CC/BCC addresses. Each can have more than one added.
em.To.Add("rp@asna.com")
em.BCC.Add("roger@asna.com")
em.CC.Add("ralph@rsisys.com")
Optionally assign attachments. The file must exist on the PC.
// em.Attachments.Add("C:\Users\roger\Documents\dbnames.txt")
The default is to not send as important.
em.IsImportant = *True
The default is to not send as HTML.
em.IsHtml = *True
Set body and subject. If sending HTML, valid HTML tags as needed.
em.Body = "<h1>Hello, world</h1><p>Wake up momma, there's a white boat coming up the river.</p>"
em.Subject = "This was sent throught the smtp.office365.com SMTP server."
Attempt to send email.
Try
Send email.
If em.Send()
Console.WriteLine('Mail sent')
Else
If Send()
doesn’t return *True, the exception that
occurred is in the LastError property.
Console.WriteLine(em.LastError.Message)
EndIf
Catch any other exception.
Catch ex Type(System.Exception)
Console.WriteLine(ex.Message)
EndTry
EndSr
EndClass