D
Dave Hardenbrook
I am new to ASP.NET (only coded web pages in HTML in the past), and I'm
having some trouble: I have a form on which a visitor to my page can
fill out comments and send them to my E-mail box. The code works fine
when I test it on my local machine; but for the identical code deployed
to my web site (hosted on GoDaddy.com), when I click the "Submit" button
to send the E-mail, an exception is thrown containing the following
error:
Request for the permission of type 'System.Net.Mail.SmtpPermission,
System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.
I don't have the slightest idea when this means. I'm using the Express
version of VS 2008, so I cannot remotely debug the code. Does anyone
have any idea what's wrong? Here are the relevant code snippets:
Contact.aspx
---------------------
<table cellspacing="0" cellpadding="5" bgcolor="#ffe0c0">
<tbody>
<!-- (Other fields for E-mail address, etc. not shown) -->
<tr>
<td align="right">
<font face="Arial"> Write your message
here:font>
</td>
<td>
<asp:TextBox id="TB_EmailBody" runat="server"
Font-Names="Arial" Width="400px"
TextMode="MultiLine" Height="100px" Rows="5">
</asp:TextBox>
<asp:RequiredFieldValidator ID="RFV_EmailBody"
runat="server"
ControlToValidate="TB_EmailBody"
SetFocusOnError="true" />
</td>
</tr>
<tr>
<td align="center">
<asp:Button id="SubmitButton"
OnClick="SendFeedbackEmail" runat="server"
Text="Submit"
Style="z-index: 100; left: -35px; position:
relative; top: 0px" Width="150px" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="MessageLabel" runat="server"
Style="z-index: 100; left: 0px; position: relative;
top: 0px" Text="">
</asp:Label>
</td>
</tr>
</tbody>
</table>
Contact.aspx.cs (* = omitted private info)
-----------------------------------------------------
// Create and Send E-mail based on user input
//
protected void SendFeedbackEmail(object sender, EventArgs e)
{
const string DaveName = "Dave Hardenbrook",
DaveAddy = "*****@*****.com";
const string password = "*****************";
try
{
SmtpClient smtpc =
new SmtpClient("smtpout.secureserver.net", 80);
MailMessage mmsg = new MailMessage();
// Create E-mail address objects, sender and recipient (= Dave)
//
MailAddress FromAddy = new MailAddress(TB_EmailFrom.Text,
TB_Name.Text);
//
MailAddress ToAddy = new MailAddress(DaveAddy, DaveName);
// Set E-mail Message params
//
mmsg.From = FromAddy;
mmsg.To.Add(ToAddy);
mmsg.Subject = TB_EmailSubject.Text;
mmsg.Body = TB_EmailBody.Text;
// Set SMTP Credentials
//
smtpc.Credentials =
new System.Net.NetworkCredential(DaveAddy, password);
// Dispatch E-mail
//
smtpc.Send(mmsg);
// Print result
//
MessageLabel.Text = "Sent!";
}
catch (Exception ex)
{
// Display Error
//
MessageLabel.Text = "Couldn't send E-mail: " + ex.Message;
}
}
having some trouble: I have a form on which a visitor to my page can
fill out comments and send them to my E-mail box. The code works fine
when I test it on my local machine; but for the identical code deployed
to my web site (hosted on GoDaddy.com), when I click the "Submit" button
to send the E-mail, an exception is thrown containing the following
error:
Request for the permission of type 'System.Net.Mail.SmtpPermission,
System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.
I don't have the slightest idea when this means. I'm using the Express
version of VS 2008, so I cannot remotely debug the code. Does anyone
have any idea what's wrong? Here are the relevant code snippets:
Contact.aspx
---------------------
<table cellspacing="0" cellpadding="5" bgcolor="#ffe0c0">
<tbody>
<!-- (Other fields for E-mail address, etc. not shown) -->
<tr>
<td align="right">
<font face="Arial"> Write your message
here:font>
</td>
<td>
<asp:TextBox id="TB_EmailBody" runat="server"
Font-Names="Arial" Width="400px"
TextMode="MultiLine" Height="100px" Rows="5">
</asp:TextBox>
<asp:RequiredFieldValidator ID="RFV_EmailBody"
runat="server"
ControlToValidate="TB_EmailBody"
SetFocusOnError="true" />
</td>
</tr>
<tr>
<td align="center">
<asp:Button id="SubmitButton"
OnClick="SendFeedbackEmail" runat="server"
Text="Submit"
Style="z-index: 100; left: -35px; position:
relative; top: 0px" Width="150px" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="MessageLabel" runat="server"
Style="z-index: 100; left: 0px; position: relative;
top: 0px" Text="">
</asp:Label>
</td>
</tr>
</tbody>
</table>
Contact.aspx.cs (* = omitted private info)
-----------------------------------------------------
// Create and Send E-mail based on user input
//
protected void SendFeedbackEmail(object sender, EventArgs e)
{
const string DaveName = "Dave Hardenbrook",
DaveAddy = "*****@*****.com";
const string password = "*****************";
try
{
SmtpClient smtpc =
new SmtpClient("smtpout.secureserver.net", 80);
MailMessage mmsg = new MailMessage();
// Create E-mail address objects, sender and recipient (= Dave)
//
MailAddress FromAddy = new MailAddress(TB_EmailFrom.Text,
TB_Name.Text);
//
MailAddress ToAddy = new MailAddress(DaveAddy, DaveName);
// Set E-mail Message params
//
mmsg.From = FromAddy;
mmsg.To.Add(ToAddy);
mmsg.Subject = TB_EmailSubject.Text;
mmsg.Body = TB_EmailBody.Text;
// Set SMTP Credentials
//
smtpc.Credentials =
new System.Net.NetworkCredential(DaveAddy, password);
// Dispatch E-mail
//
smtpc.Send(mmsg);
// Print result
//
MessageLabel.Text = "Sent!";
}
catch (Exception ex)
{
// Display Error
//
MessageLabel.Text = "Couldn't send E-mail: " + ex.Message;
}
}