Hi,
I am working on try it out exercise on page 309. Here is my code from Email.aspx.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
public partial class Email : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Test message";
myMessage.Body = "hello world,from planet wrox";
myMessage.From = new MailAddress("myemailid", "my name");
myMessage.To.Add(new MailAddress("receiver's emailid", "receiver's name"));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);
mySmtpClient.EnableSsl = true;
}
}
and here is the code, i added to web.config file
Code:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="my emailid">
<network host="smtp.myprovider.com"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
and when i run my page in to browser i get the following error
A socket operation was attempted to an unreachable network xx.xxx.xx.xxx:xx
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable network xx.xxx.xx.xxx:xx
Source Error:
Line 19:
Line 20: SmtpClient mySmtpClient = new SmtpClient();
Line 21: mySmtpClient.Send(myMessage);
Line 22: mySmtpClient.EnableSsl = true;
Line 23:
Source File: c:\BegASPNET\Site\Demos\Email.aspx.cs Line: 21
I am stuck here, can anyone help me to figure it out.
thanx in advance.
Arya