Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi tech guys
i am facing a issue while sending mail through my C# code
The error msg thrown after this this execution is smClient.Send(Msg);
"Transaction failed. The server response was: 5.7.1 <unknown[192.168.140.116]>: Client host rejected: Access denied"
can anybody help me

C#
public string SendOTPEmail(string EmailID, string OTP, string UserName)
       {
           string status = string.Empty;
           string EmailSending_Status = string.Empty;
           string UserId = string.Empty;
           string PassWord = string.Empty;
           string EmailFrom = string.Empty;
           string SMTPHost = string.Empty;
           string EmailDomain = string.Empty;
           System.Net.Mail.MailMessage Msg = new System.Net.Mail.MailMessage();
           try
           {
               {
                   UserId = "xyz";
                   PassWord = "abc";
                   EmailFrom = "abc@aaa.com";
                   EmailDomain ="aaa.com";
                   NetworkCredential basicAuthenticationInfo = new NetworkCredential(UserId, PassWord, EmailDomain);
                   SMTPHost = "abc.com";
                   string EmailFromName = "aaa.aa@ssss.com";
                   Msg.Subject = "Please complete your customer registration";
                   Msg.From = new System.Net.Mail.MailAddress(EmailFrom, EmailFromName);
                   Msg.To.Add(new System.Net.Mail.MailAddress(EmailID));
                   Msg.IsBodyHtml = true;
                   Msg.Body = " Dear Sir/Madam," + "" + "<br>" +
                                   "" + "<br>" +
                                     "TATA AIG General Insurance welcomes you to its Portal." + "" + "<br>" +
                                    "Please enter the One Time Password:" + OTP + " to complete your Registration " + "" + "" + "<br>" +
                                    "This One Time Password is valid for 24 hours." + "" + "<br>" +
                                      "" + "<br>" +
                                     "" + "<br>" +
                                "Thanks and Regards" + "<br>" +
                               "Portal Admin" + "<br>" +
                                "" + "<br>" +
                                "" + "<br>" +
                                "" + "<br>" +
                                "Note: This is a system-generated e-mail. Please do not reply back.";
                   SmtpClient smClient = new SmtpClient();
                   smClient.Host = SMTPHost;
                   smClient.Port = 587;
                   smClient.EnableSsl = false;
                   smClient.UseDefaultCredentials = false;
                   smClient.Credentials = basicAuthenticationInfo;

                   if (ValidSMTP(SMTPHost))
                   {
                       smClient.Send(Msg);

                       EmailSending_Status = "sent";
                       status = "OTP sent to your Mailbox successfully.";
                   }
                   else
                   {
                       EmailSending_Status = "Mailserver Down";
                       status = "Failed";
                   }
               }
           }

           catch (SmtpException ex)
           {
               status = ex.Message;
               EmailSending_Status = "failed";
           }
           return status;
       }
Posted
Updated 6-Jan-15 0:45am
v2
Comments
Tejas Vaishnav 6-Jan-15 6:45am    
Please do not share your confidential information like email address, password etc. over internet.

1 solution

It is something related to your firewall policy, which is not allowing you to send the mail outside the area.
Please check below links where this problem is been answered.
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/MS-SharePoint/Q_28477111.html[^]

http://forums.asp.net/t/1283299.aspx?Problem+with+sending+mail+using+smtp+server+in+c+net+[^]

Hope this will help you.
 
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