• Insights

Using Gmail for Business Continuity in Custom Apps

Kraft Kennedy

1 min read

All Insights

When preparing for disasters, one thing to consider is what would happen if your SMTP servers went down, and applications that needed to send critical emails were unable to.  We recently had a situation where some custom applications needed to continue to send mail, even though internal SMTP servers would be down.  As long as you have access to the code for your applications and a Gmail account, it’s possible to use Google’s service to send mail from your applications.  All you need to do is reference the Google SMTP server and the appropriate port, and make an SSL connection.  It’s possible that other online mail providers would work as well, but we haven’t tested others.

To add this functionality to your apps, just use the following code.  For business continuity purposes, you could first try to send messages with an internal server, and then use the Gmail code only if a connection could not be established to an internal server.

[VB.Net]

        Dim fromAddress As String = "YourAccount@gmail.com"

        Dim toAddress As String = "EmailTo"

        Dim message As New Net.Mail.MailMessage(fromAddress, toAddress)

        message.Subject = "Subject"

        message.Body = "Body"

        Dim client As New Net.Mail.SmtpClient("smtp.gmail.com", 587)

        client.EnableSsl = True

        client.Credentials = New Net.NetworkCredential("YourAccount@gmail.com", "YourPassword")

        client.Send(message)

[ASP]

Dim iMsg, iConf, Flds

Set iMsg = CreateObject("CDO.Message")

Set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields

schema = "http://schemas.microsoft.com/cdo/configuration/"


Flds.Item(schema & "sendusing") = 2


Flds.Item(schema & "smtpserver") = "smtp.gmail.com"


Flds.Item(schema & "smtpserverport") = 465


Flds.Item(schema & "smtpauthenticate") = 1


Flds.Item(schema & "sendusername") = "YourAccount@gmail.com"


Flds.Item(schema & "sendpassword") = "YourPassword"


Flds.Item(schema & "smtpusessl") = 1


Flds.Update

With iMsg


.To = "EmailTo"

.From = YourAccount@gmail.com

.Subject = "Subject"


.TextBody = "body"


.Sender = "YourAccount@gmail.com"


.Organization = "Kraft Kennedy"


.ReplyTo = "YourAccount@gmail.com"


Set .Configuration = iConf


.Send


End With

set iMsg = nothing


set iConf = nothing


set Flds = nothing