Click here to Skip to main content
15,799,257 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have written a code for sending mail. It works perfectly fine on my local host but when I uploaded it and run on my web server its not working. Please Help me ASAP. I have to give the code to the client ASAP.
Here go's the code
C#
protected void addtocart_Click1(object sender, EventArgs e)
    {
        try
        {
	CdataTable = ObjBussiness.login_validate(Session["userid"].ToString(), Session["status"].ToString(), 17, source).Tables[0];
                for (int i = 0; i < CdataTable.Rows.Count; i++)
                {
                    listemailids += CdataTable.Rows[i]["address"].ToString() + ",";
                    /////msg1.To.Add(CDataTable.Rows[i]["address"].ToString());
                }

                string ToAddress = listemailids.Remove(listemailids.Length - 1);
                MailMessage mm = new MailMessage("info@peppermintdemo.com", ToAddress);
                mm.Subject = "Order Cart";
                mm.Body = mailbody.ToString();
                mm.IsBodyHtml = true;

                SmtpClient smtp = new SmtpClient();
                smtp.Host = "127.0.0.1";

                smtp.Send(mm);

                
                Session["productid"] = "";
                Session["qty"] = "";
                Response.Redirect("thankyou.aspx");
            }
        }
        catch (System.Data.SqlClient.SqlException ex_msg)
        {
            string msg = "Error occured while login.";
            msg += ex_msg.Message;
            //throw new Exception(msg);
            Label1.Visible = true;
            Label1.Text = msg;
        }
        finally
        {

        }
    }
Posted
Updated 21-Apr-11 21:04pm
v2
Comments
nit_singh 22-Apr-11 1:29am    
If you can tell us what problem you are getting on your web server, then it will be easy to understand the problem. Another thing add another generic catch block, so that it will handle all the exception not of a particular type.
ubaidh sayed 22-Apr-11 3:03am    
Thanks nit_singh.
Its resolved.

As already pointed out, I see you are using 'Host = "127.0.0.1";' which is a localhost ip. This might not work on webserver. You need to have proper smtp server name to communicate.

Further, it can be because of other various reasons. Like: Is the port open? Firewall permissions in place?

I would suggest you to configure 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>
 
Share this answer
 
Comments
Monjurul Habib 22-Apr-11 2:55am    
seems better.my 5.
My guess is that smtp.Host is incorrect. Your web provider should be able to give you the correct address; usually something like mailhost.provider.com or similar.
 
Share this answer
 
Thanks digital man &amp;amp; Sandeep Mewara.
That worked for me :-)
Thanks a million for your time.
 
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