Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.31 KB | None | 0 0
  1. Public Module SendSMTP
  2.     Public Sub SendSMTP(ByVal strFrom As String, ByVal strTo As String, ByVal strSubject As String, ByVal strBody As String, ByVal strCC As String, ByVal strAttachments As String)
  3.         Dim insMail As New MailMessage(New MailAddress(strFrom), New MailAddress(strTo))
  4.         With insMail
  5.             .Subject = strSubject
  6.             .Body = strBody
  7.             .CC.Add(New MailAddress(strCC))
  8.             If Not strAttachments.Equals(String.Empty) Then
  9.                 Dim strFile As String
  10.                 Dim strAttach() As String = strAttachments.Split(";"c)
  11.                 For Each strFile In strAttach
  12.                     .Attachments.Add(New Attachment(strFile.Trim()))
  13.                 Next
  14.             End If
  15.         End With
  16.         Dim SmtpUser As New System.Net.NetworkCredential()
  17.         Dim smtp As New System.Net.Mail.SmtpClient
  18.         '-- Define Authenticated User
  19.         SmtpUser.UserName = "something"
  20.         SmtpUser.Password = "somepassword"
  21.         SmtpUser.Domain = "smtp.1und1.de"
  22.         '-- Send Message
  23.         smtp.UseDefaultCredentials = False
  24.         smtp.Credentials = SmtpUser
  25.         smtp.Port = 25
  26.         smtp.Send(insMail)
  27.     End Sub
  28. End Module
  29.  
  30. 'error
  31. SendSMTP("something@something.de", "flo@flo.de", "Subject", "Body here", "CC", "Attachment")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement