.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Sending Mail

Posted By: R@j     Posted Date: December 20, 2008    Points:2   Category :ASP.Net
Hi Guys, I need help.......
I wrote code for sending mail in ASP.NET(C#).And used localhost as my smtpserver
I got the following error
ERROR: transport failed to connect to server

I set all d settings as portno:25,accept mails........
Still I got error
Thanks In Advance.....

Responses
Author: Amit Mehra             
Posted Date: December 21, 2008     Points: 5   

Hi,
I guess your SMTP is not configured... chcek you SMTP configuration....also add this lines of code and see


msg.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
msg.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailexchanger.xxx.xx.us"
msg.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2



Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Shashi Ray             
Posted Date: December 22, 2008     Points: 5   

try this

Start -> Setting -> Control Panal -> Windows Firewall -> Execption -> Add Port and

write Name=SMTP and Port Number=25 than Select TCP RadioButton than OK

and try this Code

http://www.dotnetspark.com/kb/164-code-for-sending-email.aspx

Shashi Kant Ray
Author: Athira Sreejith             
Posted Date: December 31, 2008     Points: 5   

Hi..

Refer this..

Using System.Web.Mail;

private void SendMail()
{
try
{
MailMessage m_newmail = new MailMessage();
SmtpClient s_client = new SmtpClient();
string attachfile=string.Empty;
Attachment m_attach;
string attachfile1=string.Empty;
string strdir = string.Empty;
MailAddress fromAdr = new MailAddress(txtEmail.Text);
m_newmail.From = fromAdr;

string strMailId = System.Configuration.ConfigurationManager.AppSettings["MailId"].ToString();
m_newmail.To.Add(strMailId);
m_newmail.Subject = "About Enquiry";

StringBuilder MailBody = new StringBuilder();
MailBody.Append("Name :" + txtName.Text.Trim() + "<br/>");
MailBody.Append("Designation :" + txtDesgntn.Text + "<br/>");
MailBody.Append("Company Name :" + txtCoName.Text + "<br/>");
MailBody.Append("Address :" + txtAddress.Text + "<br/>");
MailBody.Append("Pin :" + txtPin.Text + "<br/>");
MailBody.Append("Country :" + txtCountry.Text + "<br/>");
MailBody.Append("Telephone :" + txtTel1.Text + "-" + txtTel2.Text + "-" + txtTel3.Text + "<br/>");
MailBody.Append("Fax :" + txtFax.Text + "<br/>");
MailBody.Append("Like to comment on :" + cmbComment.SelectedValue + "<br/>");
MailBody.Append("Suggestions :" + txtSuggestions.Text + "<br/>");
MailBody.Append("Please tell us what you are looking for in enquiry :" + chklstEnquiry.SelectedValue + "<br/>");
MailBody.Append("Additional Information :" + txtAdditionalInfo.Text + "<br/>");
MailBody.Append("How did you here about us :" + cmbSelect.SelectedValue + " <br/>");

m_newmail.Body = MailBody.ToString();
m_newmail.IsBodyHtml = true;

if(fileName.HasFile)
{
attachfile = Path.GetFileName(fileName.PostedFile.FileName);
fileName.PostedFile.SaveAs(Server.MapPath(attachfile));

m_attach = new Attachment(Server.MapPath(attachfile));

m_newmail.Attachments.Add(m_attach);
attachfile1 = attachfile;
}
s_client.Host = "localhost";
s_client.UseDefaultCredentials = true;
s_client.Send(m_newmail);

ClientScript.RegisterClientScriptBlock(this.GetType(), "Hi!", String.Format("alert('An email has successfully been sent to {0}');", m_newmail.To), true);
// ClearAll();

m_newmail.Dispose();

if (attachfile1 != null)
{
File.Delete(Server.MapPath(attachfile1));
}
}
catch (Exception ex)
{
// ClearAll();
}
}



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend