10-04-2010, 06:56 PM
A4 - Emailer
(Note: The attachment to the this tutorial i have added some more stuff than there is in this tut But nothing special <!-- s --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt="" title="Smile" /><!-- s --> )
1 Loginform (Can be found if u Create a new form and look for LoginForm)
1 Form
LoginForm list
Well mostly leave it as it is but add
1 Checkbox
What u need on Form1
2 textboxes
1 richtextbox
3 Buttons
1 OpenFileDialog
4 Labels
First of all go to your Projects Properties and go to the Settings Tab
add
Username | String | User
Password | String | User
Well here is the code for LoginForm
Form1 Code
(Note: The attachment to the this tutorial i have added some more stuff than there is in this tut But nothing special <!-- s --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt="" title="Smile" /><!-- s --> )
1 Loginform (Can be found if u Create a new form and look for LoginForm)
1 Form
LoginForm list
Well mostly leave it as it is but add
1 Checkbox
What u need on Form1
2 textboxes
1 richtextbox
3 Buttons
1 OpenFileDialog
4 Labels
First of all go to your Projects Properties and go to the Settings Tab
add
Username | String | User
Password | String | User
Well here is the code for LoginForm
Code:
Public Class LoginForm1
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim dir As New IO.DirectoryInfo("C:\Xolara's E-Mailer")
If dir.Exists Then
Else
System.IO.Directory.CreateDirectory("C:\Xolara's E-Mailer")
If PasswordTextBox.Text = "" Then
MsgBox("Please enter a valid password", MsgBoxStyle.Exclamation, "Error!")
End If
End If
If UsernameTextBox.Text.Contains("@hotmail.com") = False Then
MsgBox("Please enter a valid hotmail adress", MsgBoxStyle.Exclamation, "Error!")
Else
If CheckBox1.Checked = True Then
My.Computer.FileSystem.WriteAllText("C:\Xolara's E-Mailer\Username.txt", UsernameTextBox.Text, False)
My.Computer.FileSystem.WriteAllText("C:\Xolara's E-Mailer\Password.txt", PasswordTextBox.Text, False)
Else
' ' if the checkbox have been checked before and you remove it it will remove the username and password from the textfiles
My.Computer.FileSystem.WriteAllText("C:\Xolara's E-Mailer\Username.txt", "", False)
My.Computer.FileSystem.WriteAllText("C:\Xolara's E-Mailer\Password.txt", "", False)
End If
My.Settings.Username = UsernameTextBox.Text
My.Settings.Password = PasswordTextBox.Text
MsgBox("You have succesfully logged in", MsgBoxStyle.Information, "Succes!")
Form1.Show()
Me.Close()
End If
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
Private Sub LoginForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dir As New IO.DirectoryInfo("C:\Xolara's E-Mailer")
If dir.Exists Then
UsernameTextBox.Text = My.Computer.FileSystem.ReadAllText("C:\Xolara's E-Mailer\Username.txt")
PasswordTextBox.Text = My.Computer.FileSystem.ReadAllText("C:\Xolara's E-Mailer\Password.txt")
Else
System.IO.Directory.CreateDirectory("C:\Xolara's E-Mailer")
End If
End Sub
End Class
Form1 Code
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label4.Text = ""
OpenFileDialog1.FileName = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim message As New Net.Mail.MailMessage(My.Settings.Username, TextBox1.Text, TextBox2.Text, RichTextBox1.Text)
Dim smtp As New Net.Mail.SmtpClient("smtp.live.com", 587)
Dim user As New Net.NetworkCredential(My.Settings.Username, My.Settings.Password)
smtp.enableSsl = True
smtp.Credentials = user
smtp.port = 587
smtp.host = "smtp.live.com"
smtp.send(message)
MsgBox("Your message was Succesfully sent!", MsgBoxStyle.Information, "Succes!")
Catch ex As Exception
MsgBox("Error - " + ex.Message, MsgBoxStyle.Exclamation, "Error")
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If OpenFileDialog1.ShowDialog = System.Windows.Forms.DialogResult.Cancel Then
Else
Label4.Text = OpenFileDialog1.SafeFileName
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If OpenFileDialog1.FileName = "" Then
MsgBox("Please select an attachment", MsgBoxStyle.Exclamation, "Error")
Else
Try
Dim message As New Net.Mail.MailMessage(My.Settings.Username, TextBox1.Text, TextBox2.Text, RichTextBox1.Text)
Dim smtp As New Net.Mail.SmtpClient("smtp.live.com", 587)
Dim user As New Net.NetworkCredential(My.Settings.Username, My.Settings.Password)
Dim attach As New Net.Mail.Attachment(OpenFileDialog1.FileName)
message.Attachments.Add(attach)
smtp.EnableSsl = True
smtp.Credentials = user
smtp.Port = 587
smtp.Host = "smtp.live.com"
smtp.Send(message)
MsgBox("Your message was Succesfully sent!", MsgBoxStyle.Information, "Succes!")
Catch ex As Exception
MsgBox("Error - " + ex.Message, MsgBoxStyle.Exclamation, "Error")
End Try
End If
End Sub
Website: <!-- m --><a class="postlink" href="http://www.PBAProductions.com">http://www.PBAProductions.com</a><!-- m -->
E-Mail: <!-- e --><a href="mailtoatrick@AriSystems.Org">Patrick@AriSystems.Org</a><!-- e -->
Skype: Qwaxer
Youtube: Qwaxer
E-Mail: <!-- e --><a href="mailtoatrick@AriSystems.Org">Patrick@AriSystems.Org</a><!-- e -->
Skype: Qwaxer
Youtube: Qwaxer