Skip to content

Instantly share code, notes, and snippets.

@MrVitorF
Created August 3, 2019 01:42
Show Gist options
  • Save MrVitorF/2bcee9ebbb93566775ce7e930ecd3217 to your computer and use it in GitHub Desktop.
Save MrVitorF/2bcee9ebbb93566775ce7e930ecd3217 to your computer and use it in GitHub Desktop.
EmailSenderControl.vb
Imports EASendMail
Public Class EmailSenderControl
''' <summary>
''' Utilize um, html ou text, não insira ambos
''' </summary>
''' <param name="EmailPara"></param>
''' <param name="Assunto"></param>
''' <param name="HtmlBody"></param>
''' <param name="TextBody"></param>
Shared Sub SendSimpleEmail(ByVal EmailPara As String, ByVal Assunto As String, ByVal TextBody As String, ByVal EmailUser As String, ByVal EmailPass As String)
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()
' Set sender email address, please change it to yours
oMail.From = "SIPADM CRM System"
' Set recipient email address, please change it to yours
oMail.To = EmailPara '"email@gmail.com"
' Set email subject
oMail.Subject = Assunto '"test HTML email with attachment"
oMail.TextBody = TextBody
' Set HTML body
' Your SMTP server address
Dim oServer As New SmtpServer("smtp.gmail.com")
' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = EmailUser
oServer.Password = EmailPass
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
' If your smtp server requires SSL/TLS connection, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
Try
' Add attachment from local disk
'oMail.AddAttachment("d:\test.pdf")
' Add attachment from remote website
oMail.AddAttachment("https://sipadm.com/media/image/235/0000235.png") 'SIPADM Logo
Console.WriteLine("start to send email with attachment ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")
Catch ep As Exception
Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try
End Sub
''' <summary>
''' Utilize um, html ou text, não insira ambos
''' </summary>
''' <param name="EmailPara"></param>
''' <param name="Assunto"></param>
''' <param name="HtmlBody"></param>
''' <param name="TextBody"></param>
Shared Sub SendProblemEmail(ByVal EmailPara As String, ByVal Assunto As String, ByVal TextBody As String)
Dim oMail As New SmtpMail("SIPADM")
Dim oSmtp As New SmtpClient()
' Set sender email address, please change it to yours
oMail.From = "SIPADM CRM System"
' Set recipient email address, please change it to yours
oMail.To = EmailPara '"vitor.freitas.ai@gmail.com"
' Set email subject
oMail.Subject = Assunto '"test HTML email with attachment"
oMail.TextBody = TextBody
' Set HTML body
' Your SMTP server address
Dim oServer As New SmtpServer("smtp.gmail.com")
' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = "email@gmail.com"
oServer.Password = "password"
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
' If your smtp server requires SSL/TLS connection, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
Try
' Add attachment from local disk
'oMail.AddAttachment("d:\test.pdf")
' Add attachment from remote website
oMail.AddAttachment("https://sipadm.com/media/image/235/0000235.png") 'SIPADM Logo
Console.WriteLine("start to send email with attachment ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")
Catch ep As Exception
Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment