Advertisement
Guest User

Email Sender VB.NET - http://youtu.be/CmxLdemC1uU

a guest
Apr 25th, 2013
2,344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.04 KB | None | 0 0
  1. Imports System.Net.Mail
  2. Public Class Form1
  3.     Dim AppPath As String = New System.IO.FileInfo(Application.ExecutablePath).DirectoryName
  4.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  5.         Dim a() As String = System.IO.File.ReadAllLines(AppPath & "\accounts.txt")
  6.         Try
  7.             Dim i As Integer = 0
  8.             Do Until i = -1
  9.                 Dim b() As String = Split(a(i), "-")
  10.                 ListBox1.Items.Add(b(0) & "-" & b(1) & "-" & b(2))
  11.                 ListBox2.Items.Add(b(3))
  12.                 i = i + 1
  13.             Loop
  14.         Catch ex As Exception
  15.  
  16.         End Try
  17.         Try
  18.             Dim c() As String = System.IO.File.ReadAllLines(AppPath & "\friends.txt")
  19.             Dim z As Integer = 0
  20.             Do Until z = -1
  21.                 ListBox3.Items.Add(c(z))
  22.                 z = z + 1
  23.             Loop
  24.         Catch ex As Exception
  25.  
  26.         End Try
  27.     End Sub
  28.  
  29.     Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
  30.         Try
  31.             Dim a() As String = Split(ListBox1.Items(ListBox1.SelectedIndex), "-")
  32.             ComboBox1.Text = a(0)
  33.             TextBox1.Text = a(1)
  34.             TextBox3.Text = a(2)
  35.             TextBox2.Text = ListBox2.Items(ListBox1.SelectedIndex)
  36.  
  37.         Catch ex As Exception
  38.             MsgBox("Please Select A Valid User Account", MsgBoxStyle.Exclamation, "ERROR")
  39.         End Try
  40.     End Sub
  41.  
  42.     Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  43.         ListBox3.Items.Add(TextBox8.Text)
  44.         Try
  45.             Dim text As String = ""
  46.             Dim i As Integer = 0
  47.             Do Until i = ListBox3.Items.Count()
  48.                 text = ListBox3.Items(i) & vbCrLf & text
  49.                 i = i + 1
  50.             Loop
  51.             IO.File.WriteAllText(AppPath & "\friends.txt", text)
  52.         Catch ex As Exception
  53.  
  54.         End Try
  55.     End Sub
  56.  
  57.     Private Sub ListBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox3.SelectedIndexChanged
  58.         TextBox4.Text = ListBox3.Items(ListBox3.SelectedIndex)
  59.     End Sub
  60.  
  61.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  62.         Try
  63.             Dim line As String = ComboBox1.Text & "-" & TextBox1.Text & "-" & TextBox3.Text & TextBox2.Text & vbCrLf
  64.             Dim text As String = ""
  65.             ListBox1.Items.Add(ComboBox1.Text & "-" & TextBox1.Text & "-" & TextBox3.Text)
  66.             ListBox2.Items.Add(TextBox2.Text)
  67.             Dim i As Integer = 0
  68.             Do Until i = ListBox1.Items.Count()
  69.                 text = ListBox1.Items(i) & "-" & ListBox2.Items(i) & vbCrLf & text
  70.                 i = i + 1
  71.             Loop
  72.  
  73.             IO.File.WriteAllText(AppPath & "\accounts.txt", Text)
  74.         Catch ex As Exception
  75.             MsgBox("Could not add Email Info", MsgBoxStyle.Information, "ERROR")
  76.         End Try
  77.     End Sub
  78.  
  79.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  80.         checkdetails()
  81.  
  82.         If ComboBox1.Text = "Gmail" Then
  83.             Try
  84.                 Dim mail As New MailMessage
  85.                 mail.Subject = TextBox5.Text
  86.                 mail.Body = TextBox6.Text
  87.                 mail.To.Add(TextBox4.Text)
  88.                 mail.From = New MailAddress(TextBox3.Text)
  89.  
  90.                 Dim SMTP As New SmtpClient("smtp.gmail.com")
  91.                 SMTP.EnableSsl = True
  92.                 SMTP.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
  93.                 SMTP.Port = "587"
  94.                 SMTP.Send(mail)
  95.                 MsgBox("Sent Message To : " & TextBox4.Text, MsgBoxStyle.Information, "Sent!")
  96.             Catch ex As Exception
  97.                 MsgBox("Failed To Send Message", MsgBoxStyle.Exclamation, "ERROR")
  98.             End Try
  99.         End If
  100.  
  101.  
  102.         If ComboBox1.Text = "Hotmail" Then
  103.             Try
  104.                 Dim mail As New MailMessage
  105.                 mail.Subject = TextBox5.Text
  106.                 mail.Body = TextBox6.Text
  107.                 mail.To.Add(TextBox4.Text)
  108.                 mail.From = New MailAddress(TextBox3.Text)
  109.  
  110.                 Dim SMTP As New SmtpClient("smtp.live.com")
  111.                 SMTP.EnableSsl = True
  112.                 SMTP.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
  113.                 SMTP.Port = "587"
  114.                 SMTP.Send(mail)
  115.                 MsgBox("Sent Message To : " & TextBox4.Text, MsgBoxStyle.Information, "Sent!")
  116.             Catch ex As Exception
  117.                 MsgBox("Failed To Send Message", MsgBoxStyle.Exclamation, "ERROR")
  118.             End Try
  119.         End If
  120.  
  121.         If ComboBox1.Text = "Yahoo" Then
  122.             Try
  123.                 Dim mail As New MailMessage
  124.                 mail.Subject = TextBox5.Text
  125.                 mail.Body = TextBox6.Text
  126.                 mail.To.Add(TextBox4.Text)
  127.                 mail.From = New MailAddress(TextBox3.Text)
  128.  
  129.                 Dim SMTP As New SmtpClient("smtp.mail.yahoo.com")
  130.                 SMTP.EnableSsl = True
  131.                 SMTP.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
  132.                 SMTP.Port = "587"
  133.                 SMTP.Send(mail)
  134.                 MsgBox("Sent Message To : " & TextBox4.Text, MsgBoxStyle.Information, "Sent!")
  135.             Catch ex As Exception
  136.                 MsgBox("Failed To Send Message", MsgBoxStyle.Exclamation, "ERROR")
  137.             End Try
  138.         End If
  139.  
  140.     End Sub
  141.  
  142.  
  143.  
  144.     Public Function checkdetails()
  145.         Dim fail As String = False
  146.         Dim errmsg As String = ""
  147.         'checks email provider
  148.         If ComboBox1.Text = "Gmail" Or ComboBox1.Text = "Yahoo" Or ComboBox1.Text = "Hotmail" Then
  149.         Else
  150.             errmsg = "Select A Valid Email Service" & vbCrLf & errmsg
  151.             fail = True
  152.         End If
  153.         'end check of provider
  154.  
  155.         'check Login Details
  156.         If TextBox1.Text = "" Then
  157.             errmsg = "Enter A Valid Email Account" & vbCrLf & errmsg
  158.             fail = True
  159.         End If
  160.         If TextBox2.Text = "" Then
  161.             errmsg = "Enter A Valid Email Account Password" & vbCrLf & errmsg
  162.             fail = True
  163.         End If
  164.         'end check of login details
  165.  
  166.         'Check Email Stuff
  167.         If TextBox3.Text = "" Then
  168.             errmsg = "Enter A From Email Address" & vbCrLf & errmsg
  169.             fail = True
  170.         End If
  171.         If TextBox4.Text = "" Then
  172.             errmsg = "Enter A To Email Address" & vbCrLf & errmsg
  173.             fail = True
  174.         End If
  175.         If TextBox5.Text = "" Then
  176.             errmsg = "Enter A Subject" & vbCrLf & errmsg
  177.             fail = True
  178.         End If
  179.         If TextBox6.Text = "" Then
  180.             errmsg = "Enter A Message" & vbCrLf & errmsg
  181.             fail = True
  182.         End If
  183.         'End Check of Email Stuff
  184.  
  185.         If fail = True Then
  186.             MsgBox("Failed To Find Details!" & vbCrLf & "ERROR :" & vbCrLf & errmsg, MsgBoxStyle.Critical, "ERROR")
  187.         End If
  188.     End Function
  189. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement