locked
Easy way to get Vb.net to create an Email in/for Gmail? RRS feed

  • Question

  • My program creates a few text files. After they are created, I'd like to be able to click a button that will create an email message in Gmail, attach the files to it, insert a subject (title?) line, and allow the User to fill in the email address and some message text. The user would then send the email using Gmail.

    Robert Homes

    Tuesday, October 14, 2014 9:49 AM

Answers

  • Form1.Designer.vb code.

    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Class Form1
        Inherits System.Windows.Forms.Form
    
        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub
    
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
    
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
            Me.Button1 = New System.Windows.Forms.Button()
            Me.TextBox1 = New System.Windows.Forms.TextBox()
            Me.MaskedTextBox1 = New System.Windows.Forms.MaskedTextBox()
            Me.Label1 = New System.Windows.Forms.Label()
            Me.Label2 = New System.Windows.Forms.Label()
            Me.TextBox2 = New System.Windows.Forms.TextBox()
            Me.Label3 = New System.Windows.Forms.Label()
            Me.TextBox3 = New System.Windows.Forms.TextBox()
            Me.Label4 = New System.Windows.Forms.Label()
            Me.Label5 = New System.Windows.Forms.Label()
            Me.Label6 = New System.Windows.Forms.Label()
            Me.TextBox4 = New System.Windows.Forms.TextBox()
            Me.TextBox5 = New System.Windows.Forms.TextBox()
            Me.Label7 = New System.Windows.Forms.Label()
            Me.Label8 = New System.Windows.Forms.Label()
            Me.TextBox6 = New System.Windows.Forms.TextBox()
            Me.TextBox7 = New System.Windows.Forms.TextBox()
            Me.Label9 = New System.Windows.Forms.Label()
            Me.RadioButton1 = New System.Windows.Forms.RadioButton()
            Me.RadioButton2 = New System.Windows.Forms.RadioButton()
            Me.RadioButton3 = New System.Windows.Forms.RadioButton()
            Me.RadioButton4 = New System.Windows.Forms.RadioButton()
            Me.RadioButton5 = New System.Windows.Forms.RadioButton()
            Me.SuspendLayout()
            '
            'Button1
            '
            Me.Button1.BackColor = System.Drawing.Color.Lime
            Me.Button1.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Button1.Location = New System.Drawing.Point(10, 6)
            Me.Button1.Name = "Button1"
            Me.Button1.Size = New System.Drawing.Size(97, 88)
            Me.Button1.TabIndex = 0
            Me.Button1.Text = "Select me" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "when email" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "is ready to" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "send."
            Me.Button1.TextAlign = System.Drawing.ContentAlignment.TopCenter
            Me.Button1.UseVisualStyleBackColor = False
            '
            'TextBox1
            '
            Me.TextBox1.Font = New System.Drawing.Font("Book Antiqua", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.TextBox1.Location = New System.Drawing.Point(16, 220)
            Me.TextBox1.Name = "TextBox1"
            Me.TextBox1.Size = New System.Drawing.Size(390, 26)
            Me.TextBox1.TabIndex = 1
            '
            'MaskedTextBox1
            '
            Me.MaskedTextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.MaskedTextBox1.Location = New System.Drawing.Point(13, 294)
            Me.MaskedTextBox1.Name = "MaskedTextBox1"
            Me.MaskedTextBox1.Size = New System.Drawing.Size(390, 24)
            Me.MaskedTextBox1.TabIndex = 2
            '
            'Label1
            '
            Me.Label1.AutoSize = True
            Me.Label1.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label1.Location = New System.Drawing.Point(171, 193)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(81, 18)
            Me.Label1.TabIndex = 3
            Me.Label1.Text = "User name"
            '
            'Label2
            '
            Me.Label2.AutoSize = True
            Me.Label2.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label2.Location = New System.Drawing.Point(173, 264)
            Me.Label2.Name = "Label2"
            Me.Label2.Size = New System.Drawing.Size(75, 18)
            Me.Label2.TabIndex = 4
            Me.Label2.Text = "Password"
            '
            'TextBox2
            '
            Me.TextBox2.Font = New System.Drawing.Font("Book Antiqua", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.TextBox2.Location = New System.Drawing.Point(163, 72)
            Me.TextBox2.Name = "TextBox2"
            Me.TextBox2.Size = New System.Drawing.Size(98, 26)
            Me.TextBox2.TabIndex = 5
            '
            'Label3
            '
            Me.Label3.AutoSize = True
            Me.Label3.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label3.Location = New System.Drawing.Point(162, 28)
            Me.Label3.Name = "Label3"
            Me.Label3.Size = New System.Drawing.Size(95, 36)
            Me.Label3.TabIndex = 6
            Me.Label3.Text = "SMTP server" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "port number"
            Me.Label3.TextAlign = System.Drawing.ContentAlignment.TopCenter
            '
            'TextBox3
            '
            Me.TextBox3.Font = New System.Drawing.Font("Book Antiqua", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.TextBox3.Location = New System.Drawing.Point(98, 146)
            Me.TextBox3.Name = "TextBox3"
            Me.TextBox3.Size = New System.Drawing.Size(227, 26)
            Me.TextBox3.TabIndex = 7
            '
            'Label4
            '
            Me.Label4.AutoSize = True
            Me.Label4.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label4.Location = New System.Drawing.Point(163, 102)
            Me.Label4.Name = "Label4"
            Me.Label4.Size = New System.Drawing.Size(95, 36)
            Me.Label4.TabIndex = 8
            Me.Label4.Text = "SMTP server" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "host"
            Me.Label4.TextAlign = System.Drawing.ContentAlignment.TopCenter
            '
            'Label5
            '
            Me.Label5.AutoSize = True
            Me.Label5.BackColor = System.Drawing.Color.OrangeRed
            Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label5.Location = New System.Drawing.Point(121, 7)
            Me.Label5.Name = "Label5"
            Me.Label5.Size = New System.Drawing.Size(175, 18)
            Me.Label5.TabIndex = 9
            Me.Label5.Text = "SMTP only supports SSL"
            Me.Label5.TextAlign = System.Drawing.ContentAlignment.TopCenter
            '
            'Label6
            '
            Me.Label6.AutoSize = True
            Me.Label6.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label6.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label6.Location = New System.Drawing.Point(167, 337)
            Me.Label6.Name = "Label6"
            Me.Label6.Size = New System.Drawing.Size(86, 18)
            Me.Label6.TabIndex = 11
            Me.Label6.Text = "Mail subject"
            '
            'TextBox4
            '
            Me.TextBox4.Font = New System.Drawing.Font("Book Antiqua", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.TextBox4.Location = New System.Drawing.Point(10, 366)
            Me.TextBox4.Multiline = True
            Me.TextBox4.Name = "TextBox4"
            Me.TextBox4.Size = New System.Drawing.Size(393, 82)
            Me.TextBox4.TabIndex = 12
            '
            'TextBox5
            '
            Me.TextBox5.Font = New System.Drawing.Font("Book Antiqua", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.TextBox5.Location = New System.Drawing.Point(7, 513)
            Me.TextBox5.Multiline = True
            Me.TextBox5.Name = "TextBox5"
            Me.TextBox5.Size = New System.Drawing.Size(825, 145)
            Me.TextBox5.TabIndex = 14
            '
            'Label7
            '
            Me.Label7.AutoSize = True
            Me.Label7.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label7.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label7.Location = New System.Drawing.Point(382, 486)
            Me.Label7.Name = "Label7"
            Me.Label7.Size = New System.Drawing.Size(71, 18)
            Me.Label7.TabIndex = 13
            Me.Label7.Text = "Mail body"
            '
            'Label8
            '
            Me.Label8.AutoSize = True
            Me.Label8.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label8.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label8.Location = New System.Drawing.Point(564, 6)
            Me.Label8.Name = "Label8"
            Me.Label8.Size = New System.Drawing.Size(146, 18)
            Me.Label8.TabIndex = 15
            Me.Label8.Text = "Mail users to send to"
            '
            'TextBox6
            '
            Me.TextBox6.Font = New System.Drawing.Font("Book Antiqua", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.TextBox6.Location = New System.Drawing.Point(438, 34)
            Me.TextBox6.Multiline = True
            Me.TextBox6.Name = "TextBox6"
            Me.TextBox6.Size = New System.Drawing.Size(393, 191)
            Me.TextBox6.TabIndex = 16
            '
            'TextBox7
            '
            Me.TextBox7.Font = New System.Drawing.Font("Book Antiqua", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.TextBox7.Location = New System.Drawing.Point(440, 272)
            Me.TextBox7.Multiline = True
            Me.TextBox7.Name = "TextBox7"
            Me.TextBox7.Size = New System.Drawing.Size(393, 191)
            Me.TextBox7.TabIndex = 18
            '
            'Label9
            '
            Me.Label9.AutoSize = True
            Me.Label9.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label9.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label9.Location = New System.Drawing.Point(566, 244)
            Me.Label9.Name = "Label9"
            Me.Label9.Size = New System.Drawing.Size(155, 18)
            Me.Label9.TabIndex = 17
            Me.Label9.Text = "Mail users for reply list"
            '
            'RadioButton1
            '
            Me.RadioButton1.AutoSize = True
            Me.RadioButton1.BackColor = System.Drawing.SystemColors.ActiveCaption
            Me.RadioButton1.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.RadioButton1.Location = New System.Drawing.Point(901, 32)
            Me.RadioButton1.Name = "RadioButton1"
            Me.RadioButton1.Size = New System.Drawing.Size(97, 76)
            Me.RadioButton1.TabIndex = 19
            Me.RadioButton1.TabStop = True
            Me.RadioButton1.Text = "Delivery" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "notification" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "on" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "failure."
            Me.RadioButton1.UseVisualStyleBackColor = False
            '
            'RadioButton2
            '
            Me.RadioButton2.AutoSize = True
            Me.RadioButton2.BackColor = System.Drawing.SystemColors.ActiveCaption
            Me.RadioButton2.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.RadioButton2.Location = New System.Drawing.Point(900, 114)
            Me.RadioButton2.Name = "RadioButton2"
            Me.RadioButton2.Size = New System.Drawing.Size(97, 76)
            Me.RadioButton2.TabIndex = 20
            Me.RadioButton2.TabStop = True
            Me.RadioButton2.Text = "Delivery" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "notification" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "on" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "success."
            Me.RadioButton2.UseVisualStyleBackColor = False
            '
            'RadioButton3
            '
            Me.RadioButton3.AutoSize = True
            Me.RadioButton3.BackColor = System.Drawing.SystemColors.ActiveCaption
            Me.RadioButton3.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.RadioButton3.Location = New System.Drawing.Point(899, 194)
            Me.RadioButton3.Name = "RadioButton3"
            Me.RadioButton3.Size = New System.Drawing.Size(97, 76)
            Me.RadioButton3.TabIndex = 21
            Me.RadioButton3.TabStop = True
            Me.RadioButton3.Text = "Delivery" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "notification" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "on" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "delay."
            Me.RadioButton3.UseVisualStyleBackColor = False
            '
            'RadioButton4
            '
            Me.RadioButton4.AutoSize = True
            Me.RadioButton4.BackColor = System.Drawing.SystemColors.ActiveCaption
            Me.RadioButton4.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.RadioButton4.Location = New System.Drawing.Point(899, 275)
            Me.RadioButton4.Name = "RadioButton4"
            Me.RadioButton4.Size = New System.Drawing.Size(97, 58)
            Me.RadioButton4.TabIndex = 22
            Me.RadioButton4.TabStop = True
            Me.RadioButton4.Text = "Delivery" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "notification" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "NONE."
            Me.RadioButton4.UseVisualStyleBackColor = False
            '
            'RadioButton5
            '
            Me.RadioButton5.AutoSize = True
            Me.RadioButton5.BackColor = System.Drawing.SystemColors.ActiveCaption
            Me.RadioButton5.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.RadioButton5.Location = New System.Drawing.Point(899, 339)
            Me.RadioButton5.Name = "RadioButton5"
            Me.RadioButton5.Size = New System.Drawing.Size(97, 58)
            Me.RadioButton5.TabIndex = 23
            Me.RadioButton5.TabStop = True
            Me.RadioButton5.Text = "Delivery" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "notification" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "NEVER."
            Me.RadioButton5.UseVisualStyleBackColor = False
            '
            'Form1
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(1049, 660)
            Me.Controls.Add(Me.RadioButton5)
            Me.Controls.Add(Me.RadioButton4)
            Me.Controls.Add(Me.RadioButton3)
            Me.Controls.Add(Me.RadioButton2)
            Me.Controls.Add(Me.RadioButton1)
            Me.Controls.Add(Me.TextBox7)
            Me.Controls.Add(Me.Label9)
            Me.Controls.Add(Me.TextBox6)
            Me.Controls.Add(Me.Label8)
            Me.Controls.Add(Me.TextBox5)
            Me.Controls.Add(Me.Label7)
            Me.Controls.Add(Me.TextBox4)
            Me.Controls.Add(Me.Label6)
            Me.Controls.Add(Me.Label5)
            Me.Controls.Add(Me.Label4)
            Me.Controls.Add(Me.TextBox3)
            Me.Controls.Add(Me.Label3)
            Me.Controls.Add(Me.TextBox2)
            Me.Controls.Add(Me.Label2)
            Me.Controls.Add(Me.Label1)
            Me.Controls.Add(Me.MaskedTextBox1)
            Me.Controls.Add(Me.TextBox1)
            Me.Controls.Add(Me.Button1)
            Me.Name = "Form1"
            Me.Text = "Form1"
            Me.ResumeLayout(False)
            Me.PerformLayout()
    
        End Sub
        Friend WithEvents Button1 As System.Windows.Forms.Button
        Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
        Friend WithEvents MaskedTextBox1 As System.Windows.Forms.MaskedTextBox
        Friend WithEvents Label1 As System.Windows.Forms.Label
        Friend WithEvents Label2 As System.Windows.Forms.Label
        Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
        Friend WithEvents Label3 As System.Windows.Forms.Label
        Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
        Friend WithEvents Label4 As System.Windows.Forms.Label
        Friend WithEvents Label5 As System.Windows.Forms.Label
        Friend WithEvents Label6 As System.Windows.Forms.Label
        Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
        Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
        Friend WithEvents Label7 As System.Windows.Forms.Label
        Friend WithEvents Label8 As System.Windows.Forms.Label
        Friend WithEvents TextBox6 As System.Windows.Forms.TextBox
        Friend WithEvents TextBox7 As System.Windows.Forms.TextBox
        Friend WithEvents Label9 As System.Windows.Forms.Label
        Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
        Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
        Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
        Friend WithEvents RadioButton4 As System.Windows.Forms.RadioButton
        Friend WithEvents RadioButton5 As System.Windows.Forms.RadioButton
    
    End Class
    

    Top image is email sent to me via vb.net sending an email to myself using my gmail account. I didn't add any attachments to it though.

    Bottom image is app.


    La vida loca

    Thursday, October 16, 2014 9:46 PM

All replies

  • Hello,

    There are TODO markers that need to be filled in below. The following link provides information for what you need for sending messages via GMail. This will give you what is needed. 

    Imports System.Net.Mail
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Using mail As New MailMessage()
                mail.From = New MailAddress("TODO")
                mail.To.Add("TODO")
                mail.Subject = "This is an email"
    
                Dim PlainMessage As AlternateView = AlternateView.CreateAlternateViewFromString("Hello, plain text", Nothing, "text/plain")
                Dim HtmlMessage As AlternateView = AlternateView.CreateAlternateViewFromString(
                    "This is an automated email, please do not respond<br><br>This is a test <br>" &
                    "<span style=""font-weight: bold; padding-left: 20px;padding-right:5px"">Some bold text</span>" & _
                    "Non bold<br><span style=""font-weight: bold; padding-left: 5px;padding-right:5px"">Second line</span>" & _
                    "This is Kate below<br><span style=""font-weight: bold; padding-left: 70px;padding-right:5px"">" & _
                    "<img src=cid:Kate>", Nothing, "text/html")
    
                Dim Logo As New LinkedResource(IO.Path.Combine(Application.StartupPath, "Kate.jpg"), "image/jpeg")
                Logo.ContentId = "Kate"
    
                mail.AlternateViews.Add(PlainMessage)
                mail.AlternateViews.Add(HtmlMessage)
                Using smtp As New SmtpClient("TODO")
                    smtp.Send(mail)
                End Using
            End Using
    
            MsgBox("Sent")
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Tuesday, October 14, 2014 11:09 AM
  • I just used the code below, altered for Outlook, to send an email with an attachment to myself using my outlook account.

    It required port 587 and this for the SmtpServer.Host "smtp.live.com". And appropriate emailname@outlook.com in appropriate fields.

    I didn't provide a display name in the mail.From line so I only used the first field.

    Code is from Code Project article - How to Send Mails from your GMAIL Account through VB.NET or C#. Windows Programming, with a Bit of Customization

    For gmail ssl you use port 465 and for tls you use port 587 supposedly. I didn't check to see if the parameter SmtpServer.EnableSsl could be changed to SmtpServer.EnableTls. Ssl is the predecessor of Tls according to Wikipedia - Transport Layer Security.

    Option Strict On
    
    Imports System.Net.Mail ' Add ref Assemblies, Framework, System.Net
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Dim mail As New MailMessage()
            Dim SmtpServer As New SmtpClient()
            SmtpServer.Credentials = New Net.NetworkCredential("xyz@gmail.com", "password")
            SmtpServer.Port = 587 ' Other threads say to use port 465. I don't have gmail so I can't try this code.
            SmtpServer.Host = "smtp.gmail.com"
            SmtpServer.EnableSsl = True
    
            mail = New MailMessage()
            Try
                ' In the below line if you don't use a display name in the second field then the 2nd and 3rd fields are not necessary.
                ' The first field is the originating address.
                mail.From = New MailAddress("xyz@gmail.com", "Some display name goes here", System.Text.Encoding.UTF8)
    
                ' A list that you can add various mail addresses to for sending to.
                mail.To.Add("someoutgoingaddress@somemailserver.com")
    
                mail.Subject = "Hello"
    
                mail.Body = "Sending info"
    
                ' A list you can add various attachments to for the email. Of course if the attachment sizes max out what a sender or receiver
                ' is allowed or if a receiver will not accept a certain attachment type like a .exe (a .exe in a zip file works sending the zip
                ' file usually) then issues will occur.
    
                mail.Attachments.Add(New Attachment("C:\Users\John\Desktop\SomeFileName.SomeExtension"))
    
                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
    
                ' I suppose this list is in case a delivery notification fails but not sure.
    
                mail.ReplyToList.Add("xyz@gmail.com")
    
                SmtpServer.Send(mail)
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
    
        End Sub
    
    End Class


    La vida loca





    Tuesday, October 14, 2014 1:25 PM
  • Hi Kevin,

    I have several questions to ask before I can implmement the code you sent. I'll state them below. First, here is some revised code I created based on what you prepared:

    ===================================================

        Private Sub CreateEmail()

            Using mail As New MailMessage()
                mail.From = New MailAddress("rohomes@gmail.com")
                'mail.To.Add("rohomes1@gmail.com")
                mail.Subject = "NFL Stat Sheets"

                Dim PlainMessage As AlternateView = AlternateView.CreateAlternateViewFromString("Hello, plain text", Nothing, "text/plain")

                Dim HtmlMessage As AlternateView = AlternateView.CreateAlternateViewFromString(
                    "This is an automated email, please do not respond<br><br>This is a test <br>" &
                    "<span style=""font-weight: bold; padding-left: 20px;padding-right:5px"">Some bold text</span>" & _
                    "Non bold<br><span style=""font-weight: bold; padding-left: 5px;padding-right:5px"">Second line</span>" & _
                    "This is Kate below<br><span style=""font-weight: bold; padding-left: 70px;padding-right:5px"">" & _
                    "<img src=cid:Kate>", Nothing, "text/html")

                'Dim Logo As New LinkedResource(IO.Path.Combine(Application.StartupPath, "Kate.jpg"), "image/jpeg")
                'Logo.ContentId = "Kate"

                mail.AlternateViews.Add(PlainMessage)
                mail.AlternateViews.Add(HtmlMessage)

                'Using smtp As New SmtpClient("TODO")
                '    smtp.Send(mail)
                'End Using
                'MsgBox("Sent")

            End Using

        End Sub

    ==========================================================

    I hope you are able to see that I commented out several lines of your code; that's hard to see, but you have to look for the single quote mark (') at the start of some of the lines.

    I really didn't want to actually SEND the email, only to PREPARE one and call it up in Gmail so it could be completed before sending it manually. Thus, I didn't need or want the stuff about actually sending it or displaying a message that it had been "sent".

    Also, I need a way to call up Gmail after the message is "prepared". Because your code just SENDS it right away, you obviously saw no need to programmatically display the Gmail program. But I don't know how to do that, and need help with that.

    Another point concerns the lines mentioning "Kate" and/or "logo". I'm assuming those were meant as a sample of how to attach the files I want to attach to the email. Is that correct?

    Thanks fo your help.

    Robert Homes



    Robert Homes


    • Edited by Robert Homes Wednesday, October 15, 2014 11:05 PM
    Wednesday, October 15, 2014 11:04 PM
  • i just tried this code and it didnt work for me    :/
    Wednesday, October 15, 2014 11:07 PM
  • Can you post the code you used. Minus confidential information such as usernames and passwords?

    Thanks, Jayson Furr Jayson.Furr@FuJeSolutions.com

    Wednesday, October 15, 2014 11:19 PM
  • I thought I just did! But - oops - I left my personal email in there, but I don't mind, just speaking for myself.

    Robert Homes

    Wednesday, October 15, 2014 11:58 PM
  • Hello,

    First off using "it didn't work for me" could mean anything so it is always wise to indicate exactly what did not work in the future.

    Okay, SMTP is all about sending messages immediately, it knows nothing about GMail, Yahoo etc so what you are looking for is not with SMTP You would need to use GMail API calls (which I have not looked to see if it is possible even with this) to see if this is possible. The first thing that makes me think you can not in a Windows forms project is the API is RESTFUL which means you would need to write a service perhaps with WCF. If you have never done RESTFULL and/or a web service there is a good deal to learn. The main thing is not so much the code but doing the endpoints correctly. 

    Most likely not the answer you were looking for but that is the best I can do, provide possibilities.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Thursday, October 16, 2014 12:22 AM
  • What you would want to do is use the Users.drafts: create Gmail API found at https://developers.google.com/gmail/api/v1/reference/users/drafts/create#examples to create the draft then use the Users.drafts: get Gmail API found at https://developers.google.com/gmail/api/v1/reference/users/drafts/get#examples to get the id and use that to open a web browser to the correctly formatted url.

    Thanks, Jayson Furr Jayson.Furr@FuJeSolutions.com


    • Edited by Jayson Furr Thursday, October 16, 2014 12:46 AM typo
    Thursday, October 16, 2014 12:45 AM
  • I established a basic gmail account and tried sending emails via that account using vb.net.

    1. I don't allow email accounts to stay logged on. However during some of my tests I was logged on while trying to use vb.net to also send an email. I received a notification in my gmail inbox, while logged on in internet explorer, warning me somebody had attempted to logon using my address and they knew my password. So don't be logged onto the account while testing with vb.net.

    2. I then sent an email with ssl set using port 587. It errored out. So then I logged onto my gmail account with Internet Explorer. There was an email from gmail saying that a logon was attempted by an app "blah, blah" and various things were listed that I could do. So I selected the link below (which doesn't link to anything in this thread) and IE was directed there and I selected to allow my account not to be protected by "modern security standards" which maybe means TSL since SNMP can't do TSL I don't believe. Although SSL was still used. So the link was encrypted just not to TSL standards I'm pretty sure. I suppose in an accounts settings that selection is available but the link took me right there.

    "If this was you
    You can switch to an app made by Google such as Gmail to access your account (recommended) or change your settings at https://www.google.com/settings/security/lesssecureappsso that your account is no longer protected by modern security standards."

    So this is the code I used.

    I'm posting another post with the Forms designer code. Then you can create a new project and just add a Form to it. Then show the code window for Form1.Designer.vb. In solution explorer in the toolbar for it click on show all files. Then in solution explorer click on the triangle point right to Form1 and it will angle down and you'll see Form1.Designer.vb. Click on that and the designer code window should show.

    Copy and paste over all the code in the Form1.Designer.vb file the code in my next post. It will add all the controls to your Form and resize your Form too. Then copy and paste the below code in Form1's code window.

    NOTE: I just tested the code sending two image attachments. Then logged onto my gmail account. Both attachments were displayed.

    Form1 code.

    Option Strict On
    
    Imports System.Net.Mail ' Add ref Assemblies, Framework, System.Net
    
    ' Link for getting email settings. Search for other mail server settings if necessary at link.
    ' http://email.about.com/od/accessinggmail/f/Gmail_SMTP_Settings.htm
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
            TextBox2.Text = "587"
            TextBox3.Text = "smtp.gmail.com"
            MaskedTextBox1.PasswordChar = CChar("*")
            RadioButton1.Checked = True
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Button1.Enabled = False
            Button1.BackColor = Color.OrangeRed
            Button1.Text = "Mail is" & vbCrLf & "being" & vbCrLf & "SENT!"
            Dim mail As New MailMessage()
            Dim SmtpServer As New SmtpClient()
            SmtpServer.Credentials = New Net.NetworkCredential(TextBox1.Text, MaskedTextBox1.Text)
            SmtpServer.Port = CInt(TextBox2.Text) ' Some threads say to use port 587 and others 465. I don't have gmail so I can't try this code.
            SmtpServer.Host = TextBox3.Text
            SmtpServer.EnableSsl = True
    
            mail = New MailMessage()
            Try
                ' In the below line if you don't use a display name in the second field then the 2nd and 3rd fields are not necessary.
                ' The first field is the originating address.
                mail.From = New MailAddress(TextBox1.Text) ' ", "Some display name goes here", System.Text.Encoding.UTF8)
    
                ' A list that you can add various mail addresses to for sending to.
                For i = 0 To TextBox6.Lines.Count - 1
                    mail.To.Add(TextBox6.Lines(i))
                Next
    
                mail.Subject = TextBox4.Text
    
                mail.Body = TextBox5.Text
    
                ' A list you can add various attachments to for the email. Of course if the attachment sizes max out what a sender or receiver
                ' is allowed or if a receiver will not accept a certain attachment type like a .exe (a .exe in a zip file works sending the zip
                ' file usually) then issues will occur.
                If MessageBox.Show("Would you like to add attachments?", "Add email attachments", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = Windows.Forms.DialogResult.OK Then
                    Dim OFD As New OpenFileDialog
                    OFD.Multiselect = True
                    OFD.InitialDirectory = "C:\Users\John\Desktop"
                    OFD.Title = "Add mail attachments."
                    Do Until OFD.ShowDialog = Windows.Forms.DialogResult.Cancel
                        For Each Item In OFD.FileNames
                            mail.Attachments.Add(New Attachment(Item))
                        Next
                    Loop
                    OFD.Dispose()
                End If
    
                If RadioButton1.Checked Then
                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
                ElseIf RadioButton2.Checked Then
                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess
                ElseIf RadioButton3.Checked Then
                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Delay
                ElseIf RadioButton4.Checked Then
                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.None
                ElseIf RadioButton5.Checked Then
                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Never
                End If
    
                ' I suppose this list is in case a delivery notification fails but not sure.
                If TextBox7.Text <> "" Then
                    For i = 0 To TextBox7.Lines.Count - 1
                        mail.ReplyToList.Add(TextBox7.Lines(i))
                    Next
                End If
                SmtpServer.Send(mail)
                Button1.Enabled = True
                Button1.BackColor = Color.Lime
                Button1.Text = "Select me" & vbCrLf & "when email" & vbCrLf & "is ready to" & vbCrLf & "send."
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
                Button1.Enabled = True
                Button1.BackColor = Color.Lime
                Button1.Text = "Select me" & vbCrLf & "when email" & vbCrLf & "is ready to" & vbCrLf & "send."
            End Try
    
        End Sub
    
        Private Sub RadioButtons_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged, RadioButton4.CheckedChanged, RadioButton5.CheckedChanged
            For Each Ctl As RadioButton In Me.Controls.OfType(Of RadioButton)()
                Ctl.BackColor = SystemColors.ActiveCaption
            Next
            If DirectCast(sender, RadioButton).Checked Then
                DirectCast(sender, RadioButton).BackColor = Color.Lime
            End If
        End Sub
    
    End Class
    


    La vida loca



    • Edited by Mr. Monkeyboy Thursday, October 16, 2014 10:08 PM Altered code and added NOTE
    Thursday, October 16, 2014 9:37 PM
  • Form1.Designer.vb code.

    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Class Form1
        Inherits System.Windows.Forms.Form
    
        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub
    
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
    
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
            Me.Button1 = New System.Windows.Forms.Button()
            Me.TextBox1 = New System.Windows.Forms.TextBox()
            Me.MaskedTextBox1 = New System.Windows.Forms.MaskedTextBox()
            Me.Label1 = New System.Windows.Forms.Label()
            Me.Label2 = New System.Windows.Forms.Label()
            Me.TextBox2 = New System.Windows.Forms.TextBox()
            Me.Label3 = New System.Windows.Forms.Label()
            Me.TextBox3 = New System.Windows.Forms.TextBox()
            Me.Label4 = New System.Windows.Forms.Label()
            Me.Label5 = New System.Windows.Forms.Label()
            Me.Label6 = New System.Windows.Forms.Label()
            Me.TextBox4 = New System.Windows.Forms.TextBox()
            Me.TextBox5 = New System.Windows.Forms.TextBox()
            Me.Label7 = New System.Windows.Forms.Label()
            Me.Label8 = New System.Windows.Forms.Label()
            Me.TextBox6 = New System.Windows.Forms.TextBox()
            Me.TextBox7 = New System.Windows.Forms.TextBox()
            Me.Label9 = New System.Windows.Forms.Label()
            Me.RadioButton1 = New System.Windows.Forms.RadioButton()
            Me.RadioButton2 = New System.Windows.Forms.RadioButton()
            Me.RadioButton3 = New System.Windows.Forms.RadioButton()
            Me.RadioButton4 = New System.Windows.Forms.RadioButton()
            Me.RadioButton5 = New System.Windows.Forms.RadioButton()
            Me.SuspendLayout()
            '
            'Button1
            '
            Me.Button1.BackColor = System.Drawing.Color.Lime
            Me.Button1.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Button1.Location = New System.Drawing.Point(10, 6)
            Me.Button1.Name = "Button1"
            Me.Button1.Size = New System.Drawing.Size(97, 88)
            Me.Button1.TabIndex = 0
            Me.Button1.Text = "Select me" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "when email" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "is ready to" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "send."
            Me.Button1.TextAlign = System.Drawing.ContentAlignment.TopCenter
            Me.Button1.UseVisualStyleBackColor = False
            '
            'TextBox1
            '
            Me.TextBox1.Font = New System.Drawing.Font("Book Antiqua", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.TextBox1.Location = New System.Drawing.Point(16, 220)
            Me.TextBox1.Name = "TextBox1"
            Me.TextBox1.Size = New System.Drawing.Size(390, 26)
            Me.TextBox1.TabIndex = 1
            '
            'MaskedTextBox1
            '
            Me.MaskedTextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.MaskedTextBox1.Location = New System.Drawing.Point(13, 294)
            Me.MaskedTextBox1.Name = "MaskedTextBox1"
            Me.MaskedTextBox1.Size = New System.Drawing.Size(390, 24)
            Me.MaskedTextBox1.TabIndex = 2
            '
            'Label1
            '
            Me.Label1.AutoSize = True
            Me.Label1.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label1.Location = New System.Drawing.Point(171, 193)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(81, 18)
            Me.Label1.TabIndex = 3
            Me.Label1.Text = "User name"
            '
            'Label2
            '
            Me.Label2.AutoSize = True
            Me.Label2.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label2.Location = New System.Drawing.Point(173, 264)
            Me.Label2.Name = "Label2"
            Me.Label2.Size = New System.Drawing.Size(75, 18)
            Me.Label2.TabIndex = 4
            Me.Label2.Text = "Password"
            '
            'TextBox2
            '
            Me.TextBox2.Font = New System.Drawing.Font("Book Antiqua", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.TextBox2.Location = New System.Drawing.Point(163, 72)
            Me.TextBox2.Name = "TextBox2"
            Me.TextBox2.Size = New System.Drawing.Size(98, 26)
            Me.TextBox2.TabIndex = 5
            '
            'Label3
            '
            Me.Label3.AutoSize = True
            Me.Label3.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label3.Location = New System.Drawing.Point(162, 28)
            Me.Label3.Name = "Label3"
            Me.Label3.Size = New System.Drawing.Size(95, 36)
            Me.Label3.TabIndex = 6
            Me.Label3.Text = "SMTP server" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "port number"
            Me.Label3.TextAlign = System.Drawing.ContentAlignment.TopCenter
            '
            'TextBox3
            '
            Me.TextBox3.Font = New System.Drawing.Font("Book Antiqua", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.TextBox3.Location = New System.Drawing.Point(98, 146)
            Me.TextBox3.Name = "TextBox3"
            Me.TextBox3.Size = New System.Drawing.Size(227, 26)
            Me.TextBox3.TabIndex = 7
            '
            'Label4
            '
            Me.Label4.AutoSize = True
            Me.Label4.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label4.Location = New System.Drawing.Point(163, 102)
            Me.Label4.Name = "Label4"
            Me.Label4.Size = New System.Drawing.Size(95, 36)
            Me.Label4.TabIndex = 8
            Me.Label4.Text = "SMTP server" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "host"
            Me.Label4.TextAlign = System.Drawing.ContentAlignment.TopCenter
            '
            'Label5
            '
            Me.Label5.AutoSize = True
            Me.Label5.BackColor = System.Drawing.Color.OrangeRed
            Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label5.Location = New System.Drawing.Point(121, 7)
            Me.Label5.Name = "Label5"
            Me.Label5.Size = New System.Drawing.Size(175, 18)
            Me.Label5.TabIndex = 9
            Me.Label5.Text = "SMTP only supports SSL"
            Me.Label5.TextAlign = System.Drawing.ContentAlignment.TopCenter
            '
            'Label6
            '
            Me.Label6.AutoSize = True
            Me.Label6.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label6.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label6.Location = New System.Drawing.Point(167, 337)
            Me.Label6.Name = "Label6"
            Me.Label6.Size = New System.Drawing.Size(86, 18)
            Me.Label6.TabIndex = 11
            Me.Label6.Text = "Mail subject"
            '
            'TextBox4
            '
            Me.TextBox4.Font = New System.Drawing.Font("Book Antiqua", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.TextBox4.Location = New System.Drawing.Point(10, 366)
            Me.TextBox4.Multiline = True
            Me.TextBox4.Name = "TextBox4"
            Me.TextBox4.Size = New System.Drawing.Size(393, 82)
            Me.TextBox4.TabIndex = 12
            '
            'TextBox5
            '
            Me.TextBox5.Font = New System.Drawing.Font("Book Antiqua", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.TextBox5.Location = New System.Drawing.Point(7, 513)
            Me.TextBox5.Multiline = True
            Me.TextBox5.Name = "TextBox5"
            Me.TextBox5.Size = New System.Drawing.Size(825, 145)
            Me.TextBox5.TabIndex = 14
            '
            'Label7
            '
            Me.Label7.AutoSize = True
            Me.Label7.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label7.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label7.Location = New System.Drawing.Point(382, 486)
            Me.Label7.Name = "Label7"
            Me.Label7.Size = New System.Drawing.Size(71, 18)
            Me.Label7.TabIndex = 13
            Me.Label7.Text = "Mail body"
            '
            'Label8
            '
            Me.Label8.AutoSize = True
            Me.Label8.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label8.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label8.Location = New System.Drawing.Point(564, 6)
            Me.Label8.Name = "Label8"
            Me.Label8.Size = New System.Drawing.Size(146, 18)
            Me.Label8.TabIndex = 15
            Me.Label8.Text = "Mail users to send to"
            '
            'TextBox6
            '
            Me.TextBox6.Font = New System.Drawing.Font("Book Antiqua", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.TextBox6.Location = New System.Drawing.Point(438, 34)
            Me.TextBox6.Multiline = True
            Me.TextBox6.Name = "TextBox6"
            Me.TextBox6.Size = New System.Drawing.Size(393, 191)
            Me.TextBox6.TabIndex = 16
            '
            'TextBox7
            '
            Me.TextBox7.Font = New System.Drawing.Font("Book Antiqua", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.TextBox7.Location = New System.Drawing.Point(440, 272)
            Me.TextBox7.Multiline = True
            Me.TextBox7.Name = "TextBox7"
            Me.TextBox7.Size = New System.Drawing.Size(393, 191)
            Me.TextBox7.TabIndex = 18
            '
            'Label9
            '
            Me.Label9.AutoSize = True
            Me.Label9.BackColor = System.Drawing.Color.PapayaWhip
            Me.Label9.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.Label9.Location = New System.Drawing.Point(566, 244)
            Me.Label9.Name = "Label9"
            Me.Label9.Size = New System.Drawing.Size(155, 18)
            Me.Label9.TabIndex = 17
            Me.Label9.Text = "Mail users for reply list"
            '
            'RadioButton1
            '
            Me.RadioButton1.AutoSize = True
            Me.RadioButton1.BackColor = System.Drawing.SystemColors.ActiveCaption
            Me.RadioButton1.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.RadioButton1.Location = New System.Drawing.Point(901, 32)
            Me.RadioButton1.Name = "RadioButton1"
            Me.RadioButton1.Size = New System.Drawing.Size(97, 76)
            Me.RadioButton1.TabIndex = 19
            Me.RadioButton1.TabStop = True
            Me.RadioButton1.Text = "Delivery" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "notification" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "on" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "failure."
            Me.RadioButton1.UseVisualStyleBackColor = False
            '
            'RadioButton2
            '
            Me.RadioButton2.AutoSize = True
            Me.RadioButton2.BackColor = System.Drawing.SystemColors.ActiveCaption
            Me.RadioButton2.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.RadioButton2.Location = New System.Drawing.Point(900, 114)
            Me.RadioButton2.Name = "RadioButton2"
            Me.RadioButton2.Size = New System.Drawing.Size(97, 76)
            Me.RadioButton2.TabIndex = 20
            Me.RadioButton2.TabStop = True
            Me.RadioButton2.Text = "Delivery" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "notification" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "on" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "success."
            Me.RadioButton2.UseVisualStyleBackColor = False
            '
            'RadioButton3
            '
            Me.RadioButton3.AutoSize = True
            Me.RadioButton3.BackColor = System.Drawing.SystemColors.ActiveCaption
            Me.RadioButton3.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.RadioButton3.Location = New System.Drawing.Point(899, 194)
            Me.RadioButton3.Name = "RadioButton3"
            Me.RadioButton3.Size = New System.Drawing.Size(97, 76)
            Me.RadioButton3.TabIndex = 21
            Me.RadioButton3.TabStop = True
            Me.RadioButton3.Text = "Delivery" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "notification" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "on" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "delay."
            Me.RadioButton3.UseVisualStyleBackColor = False
            '
            'RadioButton4
            '
            Me.RadioButton4.AutoSize = True
            Me.RadioButton4.BackColor = System.Drawing.SystemColors.ActiveCaption
            Me.RadioButton4.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.RadioButton4.Location = New System.Drawing.Point(899, 275)
            Me.RadioButton4.Name = "RadioButton4"
            Me.RadioButton4.Size = New System.Drawing.Size(97, 58)
            Me.RadioButton4.TabIndex = 22
            Me.RadioButton4.TabStop = True
            Me.RadioButton4.Text = "Delivery" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "notification" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "NONE."
            Me.RadioButton4.UseVisualStyleBackColor = False
            '
            'RadioButton5
            '
            Me.RadioButton5.AutoSize = True
            Me.RadioButton5.BackColor = System.Drawing.SystemColors.ActiveCaption
            Me.RadioButton5.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.RadioButton5.Location = New System.Drawing.Point(899, 339)
            Me.RadioButton5.Name = "RadioButton5"
            Me.RadioButton5.Size = New System.Drawing.Size(97, 58)
            Me.RadioButton5.TabIndex = 23
            Me.RadioButton5.TabStop = True
            Me.RadioButton5.Text = "Delivery" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "notification" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "NEVER."
            Me.RadioButton5.UseVisualStyleBackColor = False
            '
            'Form1
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(1049, 660)
            Me.Controls.Add(Me.RadioButton5)
            Me.Controls.Add(Me.RadioButton4)
            Me.Controls.Add(Me.RadioButton3)
            Me.Controls.Add(Me.RadioButton2)
            Me.Controls.Add(Me.RadioButton1)
            Me.Controls.Add(Me.TextBox7)
            Me.Controls.Add(Me.Label9)
            Me.Controls.Add(Me.TextBox6)
            Me.Controls.Add(Me.Label8)
            Me.Controls.Add(Me.TextBox5)
            Me.Controls.Add(Me.Label7)
            Me.Controls.Add(Me.TextBox4)
            Me.Controls.Add(Me.Label6)
            Me.Controls.Add(Me.Label5)
            Me.Controls.Add(Me.Label4)
            Me.Controls.Add(Me.TextBox3)
            Me.Controls.Add(Me.Label3)
            Me.Controls.Add(Me.TextBox2)
            Me.Controls.Add(Me.Label2)
            Me.Controls.Add(Me.Label1)
            Me.Controls.Add(Me.MaskedTextBox1)
            Me.Controls.Add(Me.TextBox1)
            Me.Controls.Add(Me.Button1)
            Me.Name = "Form1"
            Me.Text = "Form1"
            Me.ResumeLayout(False)
            Me.PerformLayout()
    
        End Sub
        Friend WithEvents Button1 As System.Windows.Forms.Button
        Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
        Friend WithEvents MaskedTextBox1 As System.Windows.Forms.MaskedTextBox
        Friend WithEvents Label1 As System.Windows.Forms.Label
        Friend WithEvents Label2 As System.Windows.Forms.Label
        Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
        Friend WithEvents Label3 As System.Windows.Forms.Label
        Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
        Friend WithEvents Label4 As System.Windows.Forms.Label
        Friend WithEvents Label5 As System.Windows.Forms.Label
        Friend WithEvents Label6 As System.Windows.Forms.Label
        Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
        Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
        Friend WithEvents Label7 As System.Windows.Forms.Label
        Friend WithEvents Label8 As System.Windows.Forms.Label
        Friend WithEvents TextBox6 As System.Windows.Forms.TextBox
        Friend WithEvents TextBox7 As System.Windows.Forms.TextBox
        Friend WithEvents Label9 As System.Windows.Forms.Label
        Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
        Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
        Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
        Friend WithEvents RadioButton4 As System.Windows.Forms.RadioButton
        Friend WithEvents RadioButton5 As System.Windows.Forms.RadioButton
    
    End Class
    

    Top image is email sent to me via vb.net sending an email to myself using my gmail account. I didn't add any attachments to it though.

    Bottom image is app.


    La vida loca

    Thursday, October 16, 2014 9:46 PM
  • Robert Homes why would you need to display the gmail program?

    That makes no sense if you want this to be mostly automated.

    You can use OpenFileDialog so the user can select the text files.

    Otherwise don't bother with any of this. Just use a webbrowser control that navigates to gmails email sign on url and let the user sign on to their account. I suspect gmail will allow a user to select files off their PC that they want to attach and then send them out.


    La vida loca

    Thursday, October 16, 2014 10:20 PM
  • Please try this.

    Imports System.Threading
    
    Public Class Form1
    
        Public allDone As ManualResetEvent = New ManualResetEvent(False)
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            WebBrowser1.Navigate(
            "mail.google.com")
            Do While (WebBrowser1.ReadyState <> WebBrowserReadyState.Complete)
                Application.DoEvents()
            Loop
            allDone.WaitOne()
    
            Dim doc As System.Windows.Forms.HtmlDocument = WebBrowser1.Document
            Dim username As HtmlElement = doc.GetElementById("Email")
    
            username.InnerText = "username"
    
            Dim pasword As HtmlElement = doc.GetElementById("passwd")
            pasword.InnerText = "password"
    
    
            Dim loginform As HtmlElement = doc.GetElementById("signIn")
            loginform.InvokeMember("submit")
        End Sub
    
        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
            allDone.Set()
        End Sub
    
    End Class


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Thursday, October 16, 2014 10:28 PM