'**************************************************************************************************** 'Usage: 'For a Zip file of the references, visit: 'http://www.schimsky.com/Classes/TheMailer/EasyMailReferences.zip 'Dim o As New TheMailer ' 'o.SetServerName = "smtp.isc2.org" 'o.SetServerAccount = "isc2services@isc2.org" 'o.SetServerPassword = "soap0624" 'o.SetServerAuthMode = TheMailer.AuthenticationMode.AuthLogin 'Dim aRecipients(10) As String 'Dim aAttachments(10) As String 'aRecipients(0) = "Schimsky@Hotmail.com" 'aAttachments(0) = "c:\z.zip" 'aAttachments(1) = "c:\z.zip" 'Dim strFromName As String = "Mr. Steve Schimsky" 'Dim strFromEmail As String = "Steve@Schimsky.com" 'Many times this address must be the same domain as the smtp server 'Dim strReplyToEmail As String = "Steve@Schimsky.com" 'Dim strSubject As String = "My Subject" 'Dim strBody As String = "Body Body Body" 'o.SendMail(aRecipients, aAttachments, strFromEmail, strFromName, strReplyToEmail, strSubject, strBody) '*************************************************************************************************** Imports Quiksoft.EasyMail.SMTP Imports Quiksoft.EasyMail.Parse Imports Quiksoft.EasyMail.POP3 Public Class TheMailer Dim smtpObj As SMTP Private server As SMTPServer Sub New() server = New SMTPServer smtpObj = New SMTP Quiksoft.EasyMail.SMTP.License.Key = "Stephen Schimsky (Single Developer)/8919297F44691273FB1B23##9777E" Quiksoft.EasyMail.POP3.License.Key = "Stephen Schimsky (Single Developer)/8919297F44691273FB1B23##9777E" Quiksoft.EasyMail.Parse.License.Key = "Stephen Schimsky (Single Developer)/8919297F44691273FB1B23##9777E" End Sub Public Enum AuthenticationMode AuthLogin = SMTPAuthMode.AuthLogin CramMD5 = SMTPAuthMode.CramMD5 None = SMTPAuthMode.None SASL = SMTPAuthMode.SASL End Enum Public Property SetServerName() As String Get Return server.Name End Get Set(ByVal Value As String) server.Name = Value End Set End Property Public Property SetServerAccount() As String Get Return server.Account End Get Set(ByVal Value As String) server.Account = Value End Set End Property Public Property SetServerPassword() As String Get Return server.Password End Get Set(ByVal Value As String) server.Password = Value End Set End Property Public Property SetServerAuthMode() As AuthenticationMode Get Return server.AuthMode End Get Set(ByVal Value As AuthenticationMode) server.AuthMode = Value End Set End Property Sub SendMail(ByVal aRecipients As Array, ByVal aAttachments As Array, ByVal strFromEmail As String, ByVal strFromName As String, ByVal strReplyToEmail As String, ByVal strSubject As String, ByVal StrBody As String) 'Add mail server... smtpObj.SMTPServers.Clear() smtpObj.SMTPServers.Add(server) Dim msgBody As New Quiksoft.EasyMail.SMTP.BodyPart Dim msgObj As New Quiksoft.EasyMail.SMTP.EmailMessage 'Add the Subject... msgObj.Subject = strSubject 'Add a normal recipient... msgObj.Recipients.Clear() Dim i As Integer For i = 0 To UBound(aRecipients) If Trim(aRecipients(i) & "") <> "" Then msgObj.Recipients.Add(aRecipients(i), "", RecipientType.To) End If Next i 'Add any attachements... msgObj.Attachments.Clear() For i = 0 To UBound(aAttachments) If Trim(aAttachments(i) & "") <> "" Then msgObj.Attachments.Add(aAttachments(i)) End If Next i 'Specify the sender.... msgObj.From.Email = strFromEmail msgObj.From.Name = strFromName msgObj.ReplyTo = strReplyToEmail 'Set message body..... msgObj.BodyParts.Clear() ' If txtHtml.Text.Trim = "" Then msgObj.BodyParts.Add(StrBody) ' Else ' msgObj.ImportBody(txtHtml.Text.Trim, Quiksoft.EasyMail.SMTP.BodyPartFormat.HTML, ImportBodyFlags.CreateAlternativeText) ' End If RetryConnection: Try 'Send the message Application.DoEvents() smtpObj.Send(msgObj) 'Catch exception errors Catch LicenseExcep As Quiksoft.EasyMail.SMTP.LicenseException MessageBox.Show("License key error: " + LicenseExcep.Message) Exit Sub Catch FileIOExcep As FileIOException MessageBox.Show("File IO error: " + FileIOExcep.Message) Exit Sub Catch SMTPAuthExcep As SMTPAuthenticationException MessageBox.Show("SMTP Authentication error: " + SMTPAuthExcep.Message) Exit Sub Catch SMTPConnectExcep As SMTPConnectionException If InStr(SMTPConnectExcep.Message.ToUpper.Trim, "CONNECTION ERROR: ERROR CONNECTING TO SERVER.") > 0 Then MsgBox("Connection error: " + SMTPConnectExcep.Message) 'txtStatus.Text = "Retrying Connection..." 'txtStatus.Refresh() GoTo RetryConnection Else MessageBox.Show("Connection error: " + SMTPConnectExcep.Message) Exit Sub End If Catch SMTPProtocolExcep As SMTPProtocolException 'txtStatus.Text = "Retrying Authentication..." 'txtStatus.Refresh() If SMTPProtocolExcep.Message.ToUpper.Trim = "550 NOT AUTHENTICATED -- CHECK YOUR MAIL FIRST" Then 'Open a Pop3 Connection and then close it. '**************************************************************************************************** '** This routine is here to handle the 550 Authentication Error that comes up from time to time ** '** while sending batch mass emails... I'm not sure why it occurs, but opening a pop3 connection ** '** and then closing it seems to fix the problem ** '**************************************************************************************************** 'The EXE of this program would not work properly when I had this routine as 'a subroutine called CHECKTHEMAIL(). So I just moved the code here Dim pop3Obj As New POP3 Try 'Connect to the mail server pop3Obj.Connect("pop3.isc2.org") 'Log onto the POP3 mail server pop3Obj.Login("isc2services@isc2.org", "soap0624", AuthMode.Plain) pop3Obj.Disconnect() GoTo RetryConnection 'Catch POP3 exception errors Catch POP3LicenseExcep As Quiksoft.EasyMail.POP3.LicenseException MessageBox.Show("POP3 License Exception: " + POP3LicenseExcep.Message) Catch AuthExcep As Quiksoft.EasyMail.POP3.POP3AuthenticationException MessageBox.Show("Authentication Exception: " + AuthExcep.Message) Catch ConnectExcep As Quiksoft.EasyMail.POP3.POP3ConnectionException MessageBox.Show("Connection Exception: " + ConnectExcep.Message) Catch ProtocolExcep As Quiksoft.EasyMail.POP3.POP3ProtocolException MessageBox.Show("Protocol Exception: " + ProtocolExcep.Message) 'Catch Parse exception errors Catch ParseLicenseExcep As Quiksoft.EasyMail.Parse.LicenseException MessageBox.Show("Parse License Exception: " + ParseLicenseExcep.Message) Catch InputStreamExcep As Quiksoft.EasyMail.Parse.InputStreamException MessageBox.Show("Input Stream Exception: " + InputStreamExcep.Message) Catch OutputStreamExcep As Quiksoft.EasyMail.Parse.OutputStreamException MessageBox.Show("Output Stream Exception: " + OutputStreamExcep.Message) Catch ParseExcep As Quiksoft.EasyMail.Parse.ParsingException MessageBox.Show("Parsing Exception: " + ParseExcep.Message) End Try Else MessageBox.Show("SMTP protocol error: " + SMTPProtocolExcep.Message) MessageBox.Show("I Will Now Retry.") GoTo RetryConnection End If ' ******************** End Routine ********************************************************************* End Try End Sub Protected Overrides Sub Finalize() If Not server Is Nothing Then server = Nothing End If If Not smtpObj Is Nothing Then smtpObj.Dispose() End If MyBase.Finalize() End Sub End Class