Click here to Skip to main content
15,902,893 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir/Madam,

Very Good Morning,

I am develop an asp.net web application in .NET 2.0.
I want to send e-mail in my application.I am Use this Code for send Email.

code:
C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label5.Visible= false;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label5.Visible= true;
        MailMessage msg = new MailMessage();

        msg.To = TextBox1.Text;
        msg.From = TextBox2.Text;
        msg.Subject = TextBox3.Text;
        msg.Body = TextBox4.Text;
        Label5.Text = "Sending...";
        SmtpMail.SmtpServer ="smtp.realpowermoney.com";

        SmtpMail.Send(msg);
        Label5.Text = "Message sent";
    }
}
Error:
<pre lang="msil">The transport failed to connect to the server.
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.Runtime.InteropServices.COMException: The transport failed to connect to the server.

Source Error:

Line 35:
Line 36:
Line 37:         SmtpMail.Send(msg);
Line 38:
Line 39:         Label5.Text = "Message sent";

Source File: e:\HostingSpaces\say2me\realpowermoney.com\wwwroot\Default.aspx.cs    Line: 37



Sir/Madam,
   How to solve the Error.Plz help Me.

With Regards,
Debapriya
Posted
Comments
raju melveetilpurayil 2-Aug-10 10:32am    
before doing anything, just do a R&D about that topic. after that try with code.
nagendrathecoder 3-Aug-10 2:18am    
You should click Accept Answer button of the answer which have really helped you.

Sounds like you haven't set yourself up to use this web server. Does it really not need a username or password ?
 
Share this answer
 
Comments
Debapriya Sahoo 3-Aug-10 0:18am    
This is solve my problem.I can send & receive email by the code.Thanks a lot code project developer.

with regards,
Debapriya
u can use this. by using the following code i sent mail.
In this case i used Gmail account.

MailMessage mail = new MailMessage();
mail.From = new MailAddress(textBoxFrom.Text);
mail.To.Add(textBoxTo.Text);
mail.Subject = textBoxSubj.Text;
mail.Body = textBoxBody.Text;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);

smtp.EnableSsl = true;
smtp.Credentials = new  NetworkCredential("Your-Gmail-account", "gmail-password");
//Your-Gmail-account="aaa@gmail.com" ,
//gmail-password="123456"

try
{
    smtp.Send(mail);
    lblStatusMsg.Text = "Message sent";
}
catch (SmtpException ex)
{
    MessageBox.Show(ex.Message, "Error: " + ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
 
Share this answer
 
Looks like you have not configured the Web.Config file for Emails, like:
XML
<configuration>
  <!-- Add the email settings to the <system.net> element -->
  <system.net>
    <mailSettings>
      <smtp>
        <network 
             host="relayServerHostname" 
             port="portNumber"
             userName="username"
             password="password" />
      </smtp>
    </mailSettings>
  </system.net>

  <system.web>
    ...
  </system.web>
</configuration>


Have a look at this article for details:
Sending Email in ASP.NET 2.0[^]
 
Share this answer
 
Imports System.Web.Mail

Here MailMessage is a class.

Private mailMsg As MailMessage = New MailMessage()
Private mailMsg.From = from@fromServer.com
Private mailMsg.To = to@toServer.com
Private mailMsg.Cc = cc@ccServer.com"
Private mailMsg.Bcc = bcc@bccServer.com
Private mailMsg.Subject = "SubjectOfTheMailString"
Private mailMsg.Body = "BodyOfTheMailString"
SmtpMail.Send(mailMsg).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900