Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

Using Gmail Account to Send Emails With Attachment

, 8 Apr 2011
Rate this:
Please Sign up or sign in to vote.
Man, that works great! I just converted it to VB.NET and also showed the Imports/Using that was needed, thanks to David's alternate. This was just what I was looking for, Thanks Abdur.Imports System.NetImports System.Net.MailPublic Class frmMain Private Sub frmMain_Load(sender As...
Man, that works great! I just converted it to VB.NET and also showed the Imports/Using that was needed, thanks to David's alternate. This was just what I was looking for, Thanks Abdur.
Imports System.Net
Imports System.Net.Mail
 
Public Class frmMain
    Private Sub frmMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
 
    End Sub
 
    Private Sub BtnSend_Click(sender As System.Object, e As System.EventArgs) Handles btnSend.Click
        Dim MailFrom As MailAddress = New MailAddress("YourName@Gmail.com")
        Dim MailTo As MailAddress = New MailAddress("TheirName@Gmail.com")
        Dim NewMsg As MailMessage = New MailMessage(MailFrom, MailTo)
 
        NewMsg.Subject = "Test From VB.Net"
        NewMsg.Body = "Ok, Did I translate from C# to VB?"
 
        'For File Attachment, more files can also be attached
        Dim Att As Attachment = New Attachment("c:\\Picture.jpg")
        NewMsg.Attachments.Add(Att)
        Dim Smtp As SmtpClient = New SmtpClient("smtp.gmail.com", 587)
        Smtp.UseDefaultCredentials = False
        Smtp.Credentials = New NetworkCredential("YourName@gmail.com", "YourPassword")
        Smtp.EnableSsl = True
        Smtp.Send(NewMsg)
 
        '   //Alternative Short Method

        'Dim Smtp As SmtpClient = New SmtpClient("smtp.gmail.com", 587)

        'Smtp.UseDefaultCredentials = False
        'Smtp.Credentials = New NetworkCredential("username", "password")
        'Smtp.EnableSsl = True
        'Smtp.Send("sender@gamil.com", "receiver", "subject", "Email Body")

    End Sub
End Class

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

BillHudson

United States United States
No Biography provided

Comments and Discussions

 
QuestionThanks A LOT ... PinmemberLenin Paily (6907069)29-Sep-13 23:09 
GeneralReason for my vote of 4 Very useful...thanks a lot for shari... PinmemberHenco Eloff19-Jun-11 23:08 
GeneralReason for my vote of 5 I'm a "curly brace" programmer but I... PinmemberKeith.Badeau8-May-11 1:33 
GeneralIn a way of speaking anything that is done differently(even ... Pinmembercharles henington4-Apr-11 23:11 
GeneralThough this cannot be considered as an alternative yet, I gu... PinmvpSandeep Mewara29-Mar-11 9:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 8 Apr 2011
Article Copyright 2011 by BillHudson
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid