Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Net.Mail
- Friend NotInheritable Class MailNotification
- Public Sub New()
- End Sub
- Public Shared Sub SendMailNotification()
- Dim xml = XDocument.Load("Config.xml")
- Dim strConn As String = xml.<config>.<dbconfig>.<dbpath>.Value
- 'create the mail message
- Dim mail As New MailMessage()
- 'set the addresses
- Dim fromAddress = xml.<config>.<emailsettings>.<emailfrom>.Value
- mail.From = New MailAddress(fromAddress.ToString())
- Dim sendTO As String = xml.<config>.<sendTo>.<to>.Value
- Dim strArrayTO() As String
- strArrayTO = Split(sendTO, ";")
- For Each email In strArrayTO
- mail.[To].Add(email)
- Next
- Dim sendCC As String = xml.<config>.<sendTo>.<cc>.Value
- Dim strArrayCC() As String
- strArrayCC = Split(sendCC, ";")
- For Each email In strArrayCC
- mail.[CC].Add(email)
- Next
- Dim path As String = xml.<config>.<FolderPath>.<path>.Value
- Dim attachmentFile As String = path + "SBProcedures_" + DateTime.Today.ToString("dd_MM_yyyy") + ".xls"
- ''// Create the file attachment for this e-mail message.
- Dim data = New Attachment(attachmentFile)
- ''// Add time stamp information for the file.
- Dim disposition = data.ContentDisposition
- disposition.CreationDate = System.IO.File.GetCreationTime(attachmentFile)
- disposition.ModificationDate = System.IO.File.GetLastWriteTime(attachmentFile)
- disposition.ReadDate = System.IO.File.GetLastAccessTime(attachmentFile)
- ''// Add the file attachment to this e-mail message.
- mail.Attachments.Add(data)
- Dim messageBody As String = xml.<config>.<emailsettings>.<emailbody>.Value
- Dim messageSubject As String = xml.<config>.<emailsettings>.<emailsubject>.Value
- 'set the content
- mail.Subject = messageSubject
- mail.Body = messageBody
- mail.IsBodyHtml = True
- 'set the server
- Dim smtpClient = xml.<config>.<emailsettings>.<smtpserver>.Value
- Dim smtp As New SmtpClient(smtpClient.ToString())
- 'send the message
- Try
- smtp.Send(mail)
- Catch exc As Exception
- End Try
- End Sub
- Protected Overrides Sub Finalize()
- MyBase.Finalize()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement