<div>and code behind is</div> <div></div> <div> <div>Imports System.Net.Mail</div> <div>Partial Class _Default</div> <div> Inherits System.Web.UI.Page</div> <div></div> <div> Protected Sub sendmail_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles sendmail.Click</div> <div> Dim mail As MailMessage = New MailMessage()</div> <div> 'mail.To.Add("jainamit.agra@gmail.com")</div> <div> mail.To.Add("hzuberi@yahoo.com")</div> <div> mail.From = New MailAddress("hrzuberi@gmail.com")</div>
<div> mail.Subject = "Email using Gmail"</div> <div></div> <div> Dim body As String</div> <div> body = "Hi, this mail is to test sending mail" + "using Gmail in ASP.NET"</div> <div> mail.Body = Body</div> <div></div> <div>
mail.IsBodyHtml = True</div> <div> Dim smtp As SmtpClient = New SmtpClient()</div> <div> smtp.Host = "smtp.gmail.com" 'Or Your SMTP Server Address</div> <div> smtp.Credentials = New System.Net.NetworkCredential("hrzuberi@gmail.com", "********")</div>
<div> smtp.EnableSsl = True</div> <div> smtp.Send(mail)</div> <div> End Sub</div> <div>End Class</div> </div> <div></div> <div>but it is not working. The user name and password is working fine. It is giving me internal server error.</div>
Yet another error The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
and it is at the line smpt.port = 587 Please help
To fix this error, you will need to do exactly as the error says and go to the .Net Framework Configuration tool in Control Panel > Administrative Tools > .Net Framework X.X Configuration > Runtime Security Policy > Adjust Zone Security.
To read more about this error. Please read article on link below:
hzuberi
Member
11 Points
37 Posts
Email
Mar 02, 2011 02:24 PM|LINK
I am trying to send email through gmail via my asp.net application. my code is as follows.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="sendmail" runat="server" Text="Send" />
<br />
</div>
</form>
</body>
</html>
<div>and code behind is</div> <div></div> <div> <div>Imports System.Net.Mail</div> <div>Partial Class _Default</div> <div> Inherits System.Web.UI.Page</div> <div></div> <div> Protected Sub sendmail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles sendmail.Click</div> <div> Dim mail As MailMessage = New MailMessage()</div> <div> 'mail.To.Add("jainamit.agra@gmail.com")</div> <div> mail.To.Add("hzuberi@yahoo.com")</div> <div> mail.From = New MailAddress("hrzuberi@gmail.com")</div> <div> mail.Subject = "Email using Gmail"</div> <div></div> <div> Dim body As String</div> <div> body = "Hi, this mail is to test sending mail" + "using Gmail in ASP.NET"</div> <div> mail.Body = Body</div> <div></div> <div> mail.IsBodyHtml = True</div> <div> Dim smtp As SmtpClient = New SmtpClient()</div> <div> smtp.Host = "smtp.gmail.com" 'Or Your SMTP Server Address</div> <div> smtp.Credentials = New System.Net.NetworkCredential("hrzuberi@gmail.com", "********")</div> <div> smtp.EnableSsl = True</div> <div> smtp.Send(mail)</div> <div> End Sub</div> <div>End Class</div> </div> <div></div> <div>but it is not working. The user name and password is working fine. It is giving me internal server error.</div>email
aptomar
Participant
1227 Points
225 Posts
Re: Email
Mar 02, 2011 04:22 PM|LINK
add
SMTP.Port=587;
below
smtp.Host = "smtp.gmail.com" 'Or Your SMTP Server Address
Hope this answer your question
Please mark as answer if this solves your problem
DevTechie.com
email
hzuberi
Member
11 Points
37 Posts
Re: Email
Mar 03, 2011 02:04 PM|LINK
aptomar
Participant
1227 Points
225 Posts
Re: Email
Mar 03, 2011 06:56 PM|LINK
Check out this article.
http://www.codeproject.com/KB/IP/SendMailUsingGmailAccount.aspx
Hope this answer your question
Please mark as answer if this solves your problem
DevTechie.com
hzuberi
Member
11 Points
37 Posts
Re: Email
Mar 03, 2011 08:17 PM|LINK
hzuberi
Member
11 Points
37 Posts
Re: Email
Mar 04, 2011 12:48 AM|LINK
aptomar
Participant
1227 Points
225 Posts
Re: Email
Mar 05, 2011 02:12 PM|LINK
Please try this:
To read more about this error. Please read article on link below:
Hope this answer your question
Please mark as answer if this solves your problem
DevTechie.com