Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[TuToRiAl] Add Attachments to your Email Sender in VB
#1
Hello guys, Welcome to my 200th post!!! Big Grin Woot Woot Pirate!

Today you will learn how to add file attachments to your VB emailing program with multiple select. Really great feature but you must be cautious of file scanner for if it is filtered through Gmails servers such as an .exe, it will be blocked without notification.

If you want to know how to make an email sender to use attachments, then Click Here

Now to get started on features:
  • Add 1 Button
  • Add 1 OpenFileDialog
  • Add Up to 3 TextBoxes for 3 Attachments. More Textboxes, More Attachments which may result in a slow emailing. Also make the textboxes all ReadOnly = True
  • Add 3 Labels, More Labels for more attachments. Label them Attachment 1 - 3.

[Image: 339ri4j.png]

Next, the code. First off, the button.

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        file = Nothing
        OpenFileDialog1.ShowDialog()
        file = OpenFileDialog1.FileNames()
        Try
        TextBox1.Text = file(0)
        Catch ex As IndexOutOfRangeException
        EndTry
        Try
            TextBox6.Text = file(1)
        Catch ex As IndexOutOfRangeException
        End Try
        Try
            TextBox7.Text = file(2)
        Catch ex As IndexOutOfRangeException
        End Try 'All this code is for adding multiple files in one shot with Try statements.
    End Sub

Next, somewhere in the middle of the code for emailing, beginning is most preferred, paste this:

Code:
If Not TextBox1.Text = Nothing Then
                Dim attach As New Attachment(TextBox1.Text)
                MyMailMessage.Attachments.Add(attach)
            End If
            If Not TextBox2.Text = Nothing Then
                Dim attach As New Attachment(TextBox2.Text)
                MyMailMessage.Attachments.Add(attach)
            End If
            If Not TextBox3.Text = Nothing Then
                Dim attach As New Attachment(TextBox3.Text)
                MyMailMessage.Attachments.Add(attach)
            End If

This code scans for the attachments if they are there or not.

Next we need to code the OpenFileDialog1.

Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        OpenFileDialog1.DefaultExt = "C:\Users\%USERNAME%\"
        OpenFileDialog1.Title = "Select File(s) to Attach"
        OpenFileDialog1.FileName = "Select Files..."
        OpenFileDialog1.MultiSelect = True
    End Sub

Wahhhhhhhhhlllllllllllllllllllaaaaaaaaaaaaaaaaa We are done. Now select multiple files from the dialog and your good!
[Image: t5BWm.png]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What could i add to my browser? [Project] XDarkCoder 3 1,434 02-16-2013, 10:10 AM
Last Post: Swift Swim
  [TuToRiAl] How to make Offline (No Internet) Captcha (Human Confirmation) [TuToRiAl] Resistance 24 12,502 08-30-2012, 10:14 PM
Last Post: Resistance
  How can i add a thread? Modestep 2 1,152 11-16-2011, 06:24 AM
Last Post: TalishHF
  {TuToRiAl} How To Verify If Your App. Was Ran As Administrator {TuToRiAl} Resistance 11 6,008 10-11-2011, 04:30 PM
Last Post: Genuine
  [Visual Basic] Send An Email [Tutorial] Coding Support 9 3,883 06-29-2011, 09:27 AM
Last Post: Black Ghost

Forum Jump:


Users browsing this thread: 1 Guest(s)