-
Jul 13th, 2008, 01:20 PM
#1
Thread Starter
Frenzied Member
Sending email via Google's GMail.
Sending email via Google's GMail.
Works on ASP.NET 2.0 and 3.5
asp Code:
Imports System.Net Imports System.Net.Mail Dim loginInfo As New NetworkCredential("yourUserName@gmail.com", "yourGMailPassword") Dim msg As New MailMessage(EmailFromTextBox.Text, EmailToTextBox.Text, EmailSubjectTextBox.Text, EmailBodyTextBox.Text) msg.IsBodyHtml = True StatusLabel.Visible = False Try Dim client As New SmtpClient("smtp.gmail.com", 587) client.EnableSsl = True client.UseDefaultCredentials = false client.Credentials = loginInfo client.Send(msg) Catch ex As SmtpException StatusLabel.Visible = True StatusLabel.Style.Add("color", "#CC0033") StatusLabel.Text = "The following error occurred: " + "<br /><br />" + ex.Message Return End Try StatusLabel.Visible = True StatusLabel.Style.Add("color", "#009966") StatusLabel.Text = "Email sent successfully."
Last edited by met0555; Jul 17th, 2008 at 01:30 PM.
-
Jul 17th, 2008, 01:29 PM
#2
Thread Starter
Frenzied Member
Re: Sending email via Google's GMail.
Send e-mail with Gmail with Attachment
asp Code:
Imports System.Net
Imports System.Net.Mail
Dim loginInfo As New NetworkCredential("yourUserName@gmail.com", "yourGMailPassword")
Dim msg As New MailMessage(EmailFromTextBox.Text, EmailToTextBox.Text, EmailSubjectTextBox.Text, EmailBodyTextBox.Text)
Dim fileatt As New Attachment(filePath)
fileatt .TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable
msg.Attachments.Add(fileatt )
msg.IsBodyHtml = True
StatusLabel.Visible = False
Try
Dim client As New SmtpClient("smtp.gmail.com", 587)
client.EnableSsl = True
client.UseDefaultCredentials = false
client.Credentials = loginInfo
client.Send(msg)
Catch ex As SmtpException
StatusLabel.Visible = True
StatusLabel.Style.Add("color", "#CC0033")
StatusLabel.Text = "The following error occurred: " + "<br /><br />" + ex.Message
Return
End Try
StatusLabel.Visible = True
StatusLabel.Style.Add("color", "#009966")
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 )
-
Feb 5th, 2010, 01:01 AM
#3
Fanatic Member
Re: Sending email via Google's GMail.
is there any way of not to provide my secret password in the code?
-
Feb 5th, 2010, 09:50 AM
#4
Thread Starter
Frenzied Member
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
-
Feb 22nd, 2010, 11:07 AM
#5
New Member
Re: Sending email via Google's GMail.
Originally Posted by HowTo
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|