Unable to dispatch E-mails...

  • Thread starter Dave Hardenbrook
  • Start date
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">&nbsp;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;
}
}
 
B

Barrie Wilson

Barrie Wilson said:
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 ...
 
J

Juan T. Llibre

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.
 
M

Mark Rae [MVP]

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.

Apologies - you're quite right, and I didn't read the entire post...

Still wouldn't go anywhere near them, though...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top