开发者

asp email System.Net.Mail

Using this code (System.Net.Mail):

SmtpClient client = new SmtpClient();
client.Send(MyMessage);

I get this error:

System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:25

Web.config entries.

Working code.

        {
    string body = "";
    body = "<table border='0' align='center' cellpadding='2' style='border-collapse: collapse' bordercolor=''#111111' width='100%' id='AutoNumber1'>";
    body = body + "<tr><td width='100%' align='center' colspan='6'><b>Feed Back Form</b></td></tr>";
    body = body + "<tr><td width='100%' colspan='6'>&nbsp;</td></tr>";
    body = body + "<tr><td width='50%' colspan='2'>Name</td><td width='50%' colspan='4'><b>" + name.Text + "</b></td></tr>";
    body = body + "<tr><td width='50%' colspan='2'>Address</td><td width='50%' colspan='4'><b>" + Address.Text + "</b></td></tr>";
    body = body + "<tr><td width='50%' colspan='2'>City</td><td width='50%' colspan='4'><b>" + City.Text + "</b></td></tr>";
    body = body + "<tr><td width='50%' colspan='2'>State</td><td width='50%' colspan='4'><b>" + State.Text + "</b></td></tr>";
    body = body + "<tr><td width='50%' colspan='2'>Country</td><td width='50%' colspan='4'><b>" + Country.Text + "</b></td></tr>";
    body = body + "<tr><td width='50%' colspan='2'>Zip/Pin Code</td><td width='50%' colspan='4'><b>" + ZipCode.Text + "</b></td></tr>";
    body = body + "<tr><td width='50%' colspan='2'>Phone</td><td width='50%' colspan='4'><b>" + Phone.Text + "</b></td></tr>";
    body = body + "<tr><td width='50%' colspan='2'>E-Mail</td><td width='50%' colspan='4'><b>" + email.Text + "</b></td></tr>";
    body = body + "<tr><td width='50%' colspan='2'>Website URL (If Any)</td><td width='50%' colspan='4'><b>" + weburl.Text + "</b></td></tr>";
    body = body + "<tr><td width='50%' colspan='2'>How did you know about Country Oven?</td>";
    body = body + "<td width='50%'><b>" + radiobutn.SelectedItem.Text + "</b></td></tr>";
    body = body + "<tr><td width='50%' colspan='2'>Your feedback/suggestions for the site</td>";
    body = body + "<td width='50%' colspan='4'><b>" + txtsugg.Text + "</b></td></tr>";
    body = body + "<tr><td width='50%' colspan='2'>Query (If you have any)</td>";
    body = body + "<td width='50%' colspan='4'><b>" + query.Text + "</b></td></tr></table>";
    MailMessage message = new MailMessage();
    message.To = "contact@xxxx.com";
    message.From = email.Text;
    message.Subject = "ContactUs Form";
    message.BodyFormat = MailFormat.Html;
    message.Body = body;
    SmtpMail.SmtpServer.Insert(0, "");
    SmtpMail.Send(message);
    // lblmsg.Text = "Message sent successfully";
    RegisterStartupScript("startupScript", "<script language=JavaScript>alert('Message sent successfully.');</script>");
  开发者_C百科  clear();
}


 <system.net>
    <mailSettings>
        <smtp deliveryMethod="Network">
        <network defaultCredentials="True" host="LocalHost" port="25" />
        </smtp>
    </mailSettings>
</system.net>

What is wrong ?


Make sure your firewall is allowing the port 25. also SMTP service is configured and running in your local machine.


Maybe you are just not running an SMTP server on your localhost.


You probably haven't got an smtp server running. Try if dumping the files on disk works:

<mailSettings>
  <smtp deliveryMethod="SpecifiedPickupDirectory">
      <specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\mail\"/>
   </smtp>
</mailSettings>

If this works, then try setting up a local mailserver and change the settings back to your current values.

These answers might help you further:

  • How to test sending emails from asp.net on development machine?
  • How can I save an email instead of sending when using SmtpClient?


If it worked correctly with the same machine before you moved away from the deprecated method then I would assume that the default configuration for the .NET send mail is different than the default configuration for the older one.

Perhaps try removing the delivery method entry in the webconfig and use the default method.

I've connected to exchange this way before and never specified anything besides a from address, a host, username, and password.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜