Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Xolara's Tutorials
#6
A4 - Emailer

(Note: The attachment to the this tutorial i have added some more stuff than there is in this tut But nothing special <!-- sSmile --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt="Smile" title="Smile" /><!-- sSmile --> )

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


Attached Files
.zip   Xolara's E-Mailer.zip (Size: 142.11 KB / Downloads: 1,059)
Website: <!-- m --><a class="postlink" href="http://www.PBAProductions.com">http://www.PBAProductions.com</a><!-- m -->
E-Mail: <!-- e --><a href="mailtoTongueatrick@AriSystems.Org">Patrick@AriSystems.Org</a><!-- e -->
Skype: Qwaxer
Youtube: Qwaxer
[Image: 2hnx8av.jpg]


Messages In This Thread
Xolara's Tutorials - by xolara - 10-01-2010, 10:14 PM
Re: Xolara's Tutorials - by xolara - 10-01-2010, 10:32 PM
Re: Xolara's Tutorials - by xolara - 10-04-2010, 03:30 PM
Re: Xolara's Tutorials - by xolara - 10-04-2010, 05:27 PM
Re: Xolara's Tutorials - by xolara - 10-04-2010, 06:56 PM
Re: Xolara's Tutorials - by xolara - 10-07-2010, 03:36 AM
Re: Xolara's Tutorials - by xolara - 01-29-2011, 01:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Step by Step tutorials of VB! Himansh 1 10,116 09-28-2011, 02:05 AM
Last Post: xolara

Forum Jump:


Users browsing this thread: 1 Guest(s)