Advertisement
AndrewAubury

Untitled

Aug 6th, 2015
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.00 KB | None | 0 0
  1. //
  2. // Simple application to send mails to any mail clients from Gmail account
  3. // Using VB.NET
  4. Imports System.Net.Mail
  5. Public Class mailform
  6.     Dim mail As New MailMessage()
  7.  
  8.    Private Sub mailform_Load(ByVal sender As System.Object, ByVal e As _
  9.                 System.EventArgs) Handles MyBase.Load
  10.         TextBox2.Text = "xyz@gmail.com"
  11.     End Sub
  12.  
  13.     Private Sub Button1_Click(ByVal sender As System.Object, _
  14.         ByVal e As System.EventArgs) Handles Button1.Click
  15.         Dim SmtpServer As New SmtpClient()
  16.         SmtpServer.Credentials = New Net.NetworkCredential
  17.                     ("xyz@gmail.com", "password")
  18.         SmtpServer.Port = 587
  19.         SmtpServer.Host = "smtp.gmail.com"
  20.         SmtpServer.EnableSsl = True
  21.  
  22.         mail = New MailMessage()
  23.         Dim addr() As String = TextBox1.Text.Split(",")
  24.         Try
  25.             mail.From = New MailAddress("xyz@gmail.com",
  26.                 "Web Developers", System.Text.Encoding.UTF8)
  27.  
  28.             Dim i As Byte
  29.             For i = 0 To addr.Length - 1
  30.                 mail.To.Add(addr(i))
  31.             Next
  32.             mail.Subject = TextBox3.Text
  33.             mail.Body = TextBox4.Text
  34.             If ListBox1.Items.Count <> 0 Then
  35.                 For i = 0 To ListBox1.Items.Count - 1
  36.                     mail.Attachments.Add(New Attachment
  37.                         (ListBox1.Items.Item(i)))
  38.                 Next
  39.             End If
  40.             mail.DeliveryNotificationOptions =
  41.                     DeliveryNotificationOptions.OnFailure
  42.             mail.ReplyTo = New MailAddress(TextBox1.Text)
  43.             SmtpServer.Send(mail)
  44.         Catch ex As Exception
  45.             MsgBox(ex.ToString())
  46.         End Try
  47.     End Sub
  48.  
  49.     Private Sub Button2_Click(ByVal sender As System.Object, _
  50.             ByVal e As System.EventArgs) Handles Button2.Click
  51.         If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
  52.             ListBox1.Items.Add(OpenFileDialog1.FileName)
  53.         End If
  54.     End Sub
  55. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement