Advertisement
Guest User

Untitled

a guest
Jul 4th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.38 KB | None | 0 0
  1. Imports System.Net.Mail
  2. Friend NotInheritable Class MailNotification
  3.     Public Sub New()
  4.  
  5.     End Sub
  6.  
  7.     Public Shared Sub SendMailNotification()
  8.  
  9.         Dim xml = XDocument.Load("Config.xml")
  10.         Dim strConn As String = xml.<config>.<dbconfig>.<dbpath>.Value
  11.  
  12.         'create the mail message
  13.         Dim mail As New MailMessage()
  14.  
  15.         'set the addresses
  16.         Dim fromAddress = xml.<config>.<emailsettings>.<emailfrom>.Value
  17.         mail.From = New MailAddress(fromAddress.ToString())
  18.  
  19.  
  20.         Dim sendTO As String = xml.<config>.<sendTo>.<to>.Value
  21.         Dim strArrayTO() As String
  22.         strArrayTO = Split(sendTO, ";")
  23.         For Each email In strArrayTO
  24.             mail.[To].Add(email)
  25.         Next
  26.  
  27.         Dim sendCC As String = xml.<config>.<sendTo>.<cc>.Value
  28.         Dim strArrayCC() As String
  29.         strArrayCC = Split(sendCC, ";")
  30.  
  31.         For Each email In strArrayCC
  32.             mail.[CC].Add(email)
  33.         Next
  34.  
  35.         Dim path As String = xml.<config>.<FolderPath>.<path>.Value
  36.  
  37.         Dim attachmentFile As String = path + "SBProcedures_" + DateTime.Today.ToString("dd_MM_yyyy") + ".xls"
  38.  
  39.         ''// Create  the file attachment for this e-mail message.
  40.         Dim data = New Attachment(attachmentFile)
  41.         ''// Add time stamp information for the file.
  42.         Dim disposition = data.ContentDisposition
  43.         disposition.CreationDate = System.IO.File.GetCreationTime(attachmentFile)
  44.         disposition.ModificationDate = System.IO.File.GetLastWriteTime(attachmentFile)
  45.         disposition.ReadDate = System.IO.File.GetLastAccessTime(attachmentFile)
  46.         ''// Add the file attachment to this e-mail message.
  47.         mail.Attachments.Add(data)
  48.  
  49.         Dim messageBody As String = xml.<config>.<emailsettings>.<emailbody>.Value
  50.         Dim messageSubject As String = xml.<config>.<emailsettings>.<emailsubject>.Value
  51.  
  52.         'set the content
  53.         mail.Subject = messageSubject
  54.         mail.Body = messageBody
  55.         mail.IsBodyHtml = True
  56.  
  57.         'set the server
  58.         Dim smtpClient = xml.<config>.<emailsettings>.<smtpserver>.Value
  59.         Dim smtp As New SmtpClient(smtpClient.ToString())
  60.  
  61.         'send the message
  62.         Try
  63.             smtp.Send(mail)
  64.         Catch exc As Exception
  65.         End Try
  66.     End Sub
  67.  
  68.     Protected Overrides Sub Finalize()
  69.         MyBase.Finalize()
  70.     End Sub
  71. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement