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;
}
}
Barrie Wilson - 09 Dec 2007 05:13 GMT
>> SmtpClient smtpc = new SmtpClient("smtpout.secureserver.net", 80);
do you really want this on port 80? try 25 and report back ...
>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
[quoted text clipped - 105 lines]
> }
> }
Barrie Wilson - 09 Dec 2007 06:35 GMT
>>> SmtpClient smtpc = new SmtpClient("smtpout.secureserver.net", 80);
>
> do you really want this on port 80? try 25 and report back ...
or maybe the server is listening on port 465 if it's secure ...
OR maybe that server just won't relay mail from a GoDaddy-hosted site ...
>>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
[quoted text clipped - 105 lines]
>> }
>> }
Eliyahu Goldin - 09 Dec 2007 10:50 GMT
See if this thread helps:
Problem with System.Net.Mail on GoDaddy
http://forums.asp.net/t/939893.aspx

Signature
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
>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
[quoted text clipped - 105 lines]
> }
> }
Mark Rae [MVP] - 09 Dec 2007 12:10 GMT
> Problem with System.Net.Mail on GoDaddy
> http://forums.asp.net/t/939893.aspx
Yet another reason to avoid them like the plague...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Juan T. Llibre - 09 Dec 2007 14:18 GMT
re:
!> Problem with System.Net.Mail on GoDaddy
That was the coder's problem, not GoDaddy's.
He was using the wrong smtp server...and the wrong port, to boot.
The coder posted the solution to his mistake in the same thread.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
>> Problem with System.Net.Mail on GoDaddy
>> http://forums.asp.net/t/939893.aspx
>
> Yet another reason to avoid them like the plague...
Mark Rae [MVP] - 09 Dec 2007 14:54 GMT
> re:
> !> Problem with System.Net.Mail on GoDaddy
[quoted text clipped - 3 lines]
>
> The coder posted the solution to his mistake in the same thread.
Apologies - you're quite right, and I didn't read the entire post...
Still wouldn't go anywhere near them, though...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Dave Hardenbrook - 11 Dec 2007 03:14 GMT
> See if this thread helps:
>
> Problem with System.Net.Mail on GoDaddy
> http://forums.asp.net/t/939893.aspx
Thanks -- Changing the server and port to what they recommend in that
thread seems to have solved the problem.
Dave