Sending mail from asp.net.. need help
-
Hi peoples, i m trying to send an mail from my application (localhost) this is my code..( i copied from website) // Command line argument must the the SMTP host. SmtpClient client = new SmtpClient("localhost"); // Specify the e-mail sender. // Create a mailing address that includes a UTF8 character // in the display name. MailAddress from = new MailAddress("hbairavan@yahoo.com", "Jane " + (char)0xD8 + " Clayton", System.Text.Encoding.UTF8); // Set destinations for the e-mail message. MailAddress to = new MailAddress("hbairavan@yahoo.com"); // Specify the message content. System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to); message.Body = "This is a test e-mail message sent by an application. "; // Include some non-ASCII characters in body and subject. string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' }); message.Body += Environment.NewLine + someArrows; message.BodyEncoding = System.Text.Encoding.UTF8; message.Subject = "test message 1" + someArrows; message.SubjectEncoding = System.Text.Encoding.UTF8; // Set the method that is called back when the send operation ends. client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback); // The userState can be any object that allows your callback // method to identify this send operation. // For this example, the userToken is a string constant. string userState = "test message1"; client.EnableSsl = false; client.UseDefaultCredentials = false; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Credentials = new System.Net.NetworkCredential(from.ToString(), "f00bar"); client.SendAsync(message, userState); after this line am getting exception that failure sending mail.. wat may be the reason.please help \ thanks in advacnce
-
Hi peoples, i m trying to send an mail from my application (localhost) this is my code..( i copied from website) // Command line argument must the the SMTP host. SmtpClient client = new SmtpClient("localhost"); // Specify the e-mail sender. // Create a mailing address that includes a UTF8 character // in the display name. MailAddress from = new MailAddress("hbairavan@yahoo.com", "Jane " + (char)0xD8 + " Clayton", System.Text.Encoding.UTF8); // Set destinations for the e-mail message. MailAddress to = new MailAddress("hbairavan@yahoo.com"); // Specify the message content. System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to); message.Body = "This is a test e-mail message sent by an application. "; // Include some non-ASCII characters in body and subject. string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' }); message.Body += Environment.NewLine + someArrows; message.BodyEncoding = System.Text.Encoding.UTF8; message.Subject = "test message 1" + someArrows; message.SubjectEncoding = System.Text.Encoding.UTF8; // Set the method that is called back when the send operation ends. client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback); // The userState can be any object that allows your callback // method to identify this send operation. // For this example, the userToken is a string constant. string userState = "test message1"; client.EnableSsl = false; client.UseDefaultCredentials = false; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Credentials = new System.Net.NetworkCredential(from.ToString(), "f00bar"); client.SendAsync(message, userState); after this line am getting exception that failure sending mail.. wat may be the reason.please help \ thanks in advacnce
Hema Bairavan wrote:
// Command line argument must the the SMTP host. SmtpClient client = new SmtpClient("localhost");
You have putted "localhost" as your SMTP Server name. I guess this is wrong. Does your SMTP Server configured properly. What is the name of the Server ? Try This link. http://support.microsoft.com/kb/323436[^]
Hema Bairavan wrote:
after this line am getting exception that failure sending mail..
Please check your server configuration as I have suggested. Thanks !
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
Hema Bairavan wrote:
// Command line argument must the the SMTP host. SmtpClient client = new SmtpClient("localhost");
You have putted "localhost" as your SMTP Server name. I guess this is wrong. Does your SMTP Server configured properly. What is the name of the Server ? Try This link. http://support.microsoft.com/kb/323436[^]
Hema Bairavan wrote:
after this line am getting exception that failure sending mail..
Please check your server configuration as I have suggested. Thanks !
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
Hi, If you are sending your mail via system.net.mail. you should use smtp server ip or smtp server name and should be configured properly on server.
Farogh Haider Web developer