Click here to Skip to main content
15,920,383 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Name space:
using System.Web.Mail;  
    MailMessage mail = new MailMessage();
        mail.To = "a@gmail.com";
        mail.From = "admin@adminio.com";
        mail.Subject = "Confirmation";
        mail.Body = "Acoount confirmed....................";
        SmtpMail.SmtpServer = "1:1:1:1";

        try
        {
            SmtpMail.Send(mail);
            Response.Write("Mail send successfully");
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }



Error occured:
The transport failed to connect to the server.

what is the reason for this error?

give me the correct problem, please

[Edited]Code is wrapped in "pre" tags[/Edited]
Posted
Updated 24-Jan-11 22:45pm
v2

Check for firewall and make sure it is not blocking the port from which you wish to send the email.
 
Share this answer
 
You are trying to have this feature from quite some time now.

It can be because of various reasons. You need to look at them one by one.
Is the port open? Firewall permissions in place?
Further make sure you have configured SMTP configuration in Web.Config:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>

If needed, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]
 
Share this answer
 
public bool SendEmail(string senderEmail, string receiverEmail, string subject, string body)
{
try
{
//MailAddress emailto = senderEmail;
MailAddress emailto = new MailAddress(receiverEmail);
//MailAddress emailfrom = receiverEmail;
MailAddress emailfrom = new MailAddress(senderEmail);
MailMessage mail = new MailMessage(senderEmail, receiverEmail);
mail.Subject = subject;

mail.Body = body;
mail.IsBodyHtml = true;
NetworkCredential basicCredential = new NetworkCredential("UserName", "Password");
SmtpClient objSmtpClient = new SmtpClient(HostAddress,PortNo);

objSmtpClient.Credentials = basicCredential;



objSmtpClient.Send(mail);
}
catch
{
return false;
}
return true;
}




stop firewall access protection
 
Share this answer
 
v2
try this:wish u it will help.



try
{
SmtpClient clientConnectionWithGmailSmtp = new SmtpClient("smtp.gmail.com");//it connect user with gmail smtp server
MailMessage mailMessage = new MailMessage();
mailMessage.From =new MailAddress(from@yahoo.com);
mailMessage.To.Add(to@yahoo.com);
mailMessage.Priority = MailPriority.High;
mailMessage.Subject = subjectTB.Text;
mailMessage.Body = messageBodyTB.Text;
if (textBox1.Text != string.Empty)
{
Attachment attachment = new Attachment(textBox1.Text);
mailMessage.Attachments.Add(attachment);
}

clientConnectionWithGmailSmtp.Port = 587;
clientConnectionWithGmailSmtp.Credentials = new System.Net.NetworkCredential("sendmailthroughc@gmail.com", "Chooseapassword");
clientConnectionWithGmailSmtp.EnableSsl = true;

clientConnectionWithGmailSmtp.Send(mailMessage);
MessageBox.Show("mail Send");
}
 
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