Results 1 to 5 of 5

Thread: Sending email via Google's GMail.

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Thumbs up Sending email via Google's GMail.

    Sending email via Google's GMail.

    Works on ASP.NET 2.0 and 3.5

    asp Code:
    1. Imports System.Net
    2. Imports System.Net.Mail
    3.  
    4. Dim loginInfo As New NetworkCredential("yourUserName@gmail.com", "yourGMailPassword")
    5. Dim msg As New MailMessage(EmailFromTextBox.Text, EmailToTextBox.Text, EmailSubjectTextBox.Text, EmailBodyTextBox.Text)
    6. msg.IsBodyHtml = True
    7. StatusLabel.Visible = False
    8.  
    9. Try
    10.     Dim client As New SmtpClient("smtp.gmail.com", 587)
    11.     client.EnableSsl = True
    12.     client.UseDefaultCredentials = false
    13.     client.Credentials = loginInfo
    14.     client.Send(msg)
    15. Catch ex As SmtpException
    16.     StatusLabel.Visible = True
    17.     StatusLabel.Style.Add("color", "#CC0033")
    18.     StatusLabel.Text = "The following error occurred: " + "<br /><br />" + ex.Message
    19.     Return
    20. End Try
    21.  
    22.     StatusLabel.Visible = True
    23.     StatusLabel.Style.Add("color", "#009966")
    24.     StatusLabel.Text = "Email sent successfully."
    Last edited by met0555; Jul 17th, 2008 at 01:30 PM.

  2. #2

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Sending email via Google's GMail.

    Send e-mail with Gmail with Attachment

    asp Code:
    1. Imports System.Net
    2. Imports System.Net.Mail
    3.  
    4. Dim loginInfo As New NetworkCredential("yourUserName@gmail.com", "yourGMailPassword")
    5. Dim msg As New MailMessage(EmailFromTextBox.Text, EmailToTextBox.Text, EmailSubjectTextBox.Text, EmailBodyTextBox.Text)
    6.  
    7. Dim fileatt As New Attachment(filePath)
    8.  
    9. fileatt .TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable
    10.  
    11. msg.Attachments.Add(fileatt )
    12.  
    13. msg.IsBodyHtml = True
    14. StatusLabel.Visible = False
    15.  
    16. Try
    17.     Dim client As New SmtpClient("smtp.gmail.com", 587)
    18.     client.EnableSsl = True
    19.     client.UseDefaultCredentials = false
    20.     client.Credentials = loginInfo
    21.     client.Send(msg)
    22. Catch ex As SmtpException
    23.     StatusLabel.Visible = True
    24.     StatusLabel.Style.Add("color", "#CC0033")
    25.     StatusLabel.Text = "The following error occurred: " + "<br /><br />" + ex.Message
    26.     Return
    27. End Try
    28.  
    29.     StatusLabel.Visible = True
    30.     StatusLabel.Style.Add("color", "#009966")
    31.     StatusLabel.Text = "Email sent successfully."
    Last edited by met0555; Apr 5th, 2009 at 01:42 PM. Reason: message.Attachments.Add(fileatt ) --> msg.Attachments.Add(fileatt )

  3. #3
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    Re: Sending email via Google's GMail.

    is there any way of not to provide my secret password in the code?

  4. #4

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Sending email via Google's GMail.

    hi,

    you must know an SMTP server that doesn't require login. But on this one it's required

  5. #5
    New Member
    Join Date
    Feb 2010
    Posts
    1

    Re: Sending email via Google's GMail.

    Quote Originally Posted by HowTo View Post
    is there any way of not to provide my secret password in the code?
    It can be set in the web.config or app.config under the <system.net><mailSettings><smtp> section if you don't want it in the code.

    See... http://weblogs.asp.net/scottgu/archi...16/432854.aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width