Smtp GMail?

vineet36

New member
Joined
Jan 14, 2010
Messages
1
Programming Experience
Beginner
I am new to this forum, so I did not know where to post this, anyways iam posting here.

I have 2 text boxes where user enters email and text respectively and a button if u click should send the text to the email specified. here is the code i have tried but its not working. can someone tell me what iam missing. Please help.

Imports System.Net.Mail

Partial Class Default2
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim sb As New StringBuilder
sb.Append("Email Address: ")
sb.Append(TextBox1.Text)
sb.AppendLine()
sb.Append("Comment:")
sb.Append(TextBox2.Text)

Try
SendMail("user@gmail.com", sb.ToString())
Catch ex As Exception
Label1.Text = "Error"
End Try
End Sub

Protected Sub SendMail(ByVal from As String, ByVal body As String)

Dim Email As New MailMessage("user@gmail.com", TextBox1.Text, "Subject of Email", body)
Dim smtpClient As SmtpClient = New SmtpClient
smtpClient.Host = "smtp.gmail.com"
smtpClient.EnableSsl = True
Dim credentials As New System.Net.NetworkCredential("user@gmail.com", "pass")
smtpClient.Credentials = credentials
smtpClient.Send(Email)
Label1.Text = "Success"
End Sub

End Class
 
Back
Top