Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Simple application to send mails to any mail clients from Gmail account
- // Using VB.NET
- Imports System.Net.Mail
- Public Class mailform
- Dim mail As New MailMessage()
- Private Sub mailform_Load(ByVal sender As System.Object, ByVal e As _
- System.EventArgs) Handles MyBase.Load
- TextBox2.Text = "xyz@gmail.com"
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, _
- ByVal e As System.EventArgs) Handles Button1.Click
- Dim SmtpServer As New SmtpClient()
- SmtpServer.Credentials = New Net.NetworkCredential
- ("xyz@gmail.com", "password")
- SmtpServer.Port = 587
- SmtpServer.Host = "smtp.gmail.com"
- SmtpServer.EnableSsl = True
- mail = New MailMessage()
- Dim addr() As String = TextBox1.Text.Split(",")
- Try
- mail.From = New MailAddress("xyz@gmail.com",
- "Web Developers", System.Text.Encoding.UTF8)
- Dim i As Byte
- For i = 0 To addr.Length - 1
- mail.To.Add(addr(i))
- Next
- mail.Subject = TextBox3.Text
- mail.Body = TextBox4.Text
- If ListBox1.Items.Count <> 0 Then
- For i = 0 To ListBox1.Items.Count - 1
- mail.Attachments.Add(New Attachment
- (ListBox1.Items.Item(i)))
- Next
- End If
- mail.DeliveryNotificationOptions =
- DeliveryNotificationOptions.OnFailure
- mail.ReplyTo = New MailAddress(TextBox1.Text)
- SmtpServer.Send(mail)
- Catch ex As Exception
- MsgBox(ex.ToString())
- End Try
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, _
- ByVal e As System.EventArgs) Handles Button2.Click
- If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
- ListBox1.Items.Add(OpenFileDialog1.FileName)
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement