Click here to Skip to main content
15,917,793 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
See more:
Hi,
i have form for sending mail from my website. The form have 3 textboxes, Name, Mail, Body, so users can send me mail with some questions about my site. when i test the page on localhost this form works perfectly but on the server trow me some error. The error is "System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable network [2607:f8b0:4003:c02::6d]:25". i dont know where is my mistake. here is my code for sending mail:

C#
MailMessage mail = new MailMessage();
        mail.To.Add("contact@emall.mk");
        mail.From = new MailAddress(txtEmail.Text);
        mail.Subject = "Порака од корисник  ";

        string Body = txtBody.Text;
        mail.Body = Body;

        mail.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
        smtp.Credentials = new System.Net.NetworkCredential
        ("contact.emallmk@gmail.com", "898261898");
        //Or your Smtp Email ID and Password
        smtp.EnableSsl = true;
        smtp.Send(mail);


hope some one will help me...
Posted
Updated 24-May-13 8:46am
v2
Comments
ZurdoDev 24-May-13 14:46pm    
Sounds like you need to ask hostgator what the proper settings are.
Sergey Alexandrovich Kryukov 24-May-13 14:50pm    
As you can see, the code is totally unrelated to HostGator, but I advised to use Web service provider's SMTP, please see my answer.
—SA

can someone help even i face same problem .
 
Share this answer
 
This would be a good question to ask HostGator customer support, but they may not take the liberty to answer you if you are using "smtp.gmail.com". Usually (if not always), Web hosting provider provide access to their own SMTP or other service and provide the users with separate accounts (pretty often unlimited number of then or limited by some sufficient number of accounts). They take responsibility for their service functionality and mush try to answer you questions if they are relevant to their service. So, I would advise to use the services of your Web service provider, HostGator or any other one.

—SA
 
Share this answer
 
Comments
thekoko89 24-May-13 14:58pm    
i post here cuz they get me realy mad hostgator live support sucks :/. i gess i should type mail.emall.mk as smtp
Sergey Alexandrovich Kryukov 24-May-13 15:07pm    
Go without customer support. Don't they have instructions on using main on the Web site? What are you looking for? Anyway, just try it. Some other HostGator users who knows what to do better? This is not very likely. :-)
—SA
Finaly i solve it here is the code it works perfectly

XML
MailMessage EmailMsg = new MailMessage();
                                EmailMsg.From = new MailAddress("fromMaill@emall.mk", "Системска порака :: еMall.mk");
                                EmailMsg.To.Add(new MailAddress(toMail@emall.mk, "Заборавена лозинка - Безбедносен код"));
                                EmailMsg.Subject = "Заборавена лозинка - Безбедносен код";
                                EmailMsg.Body = BODY;
                                EmailMsg.IsBodyHtml = true;
                                EmailMsg.Priority = MailPriority.Normal;

                                SmtpClient MailClient = new SmtpClient("mail.yourhostdomail.com");
                                MailClient.Credentials = new System.Net.NetworkCredential("emailaddress", "Passworofmail");
                                MailClient.Send(EmailMsg);
 
Share this answer
 
Comments
Alaa Embaby 15-Dec-21 3:29am    
where you added this code

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