Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Web Config:

XML
<system.net>
    <mailSettings>
      <smtp from="abc@abc.com"  >
        <network host="192.118.0.90" port="25"  userName="abc@abc.com" password="xxxxx" />
      </smtp>
    </mailSettings>
  </system.net>


C#.net Code

C#
MailMessage message = new MailMessage(FromMail, strTomail);
               message.Subject = "Feedback";
               message.IsBodyHtml = true;

               message.Body = "Dear <b>Admin</b>,<br><br> A feedback has been received with the following details:";
                  
               SmtpClient smtp = new SmtpClient();
               smtp.EnableSsl = true;

               smtp.Send(message);




Error I get like this:
The requested address is not valid in its context : 173.194.79.109:25
Posted
Updated 30-Jan-13 2:40am
v3
Comments
ZurdoDev 30-Jan-13 7:49am    
The error has a different IP than what you specified so it sounds like you have a network issue you need worked out by your network admin.
OPees 30-Jan-13 22:51pm    
Thanks ryan,

I ask Network admin but he is saying some other site mail configuration are working with same setting.!!i change my codes still there is same problem..

1 solution

hi dear,
Please use below secure mail function
C#
public bool SendEmialWithSecure(string ToEmailId, string FromEmailId, string FromName, string SenderEmailId,
       string SenderName, string Subject, string MailBody, string SMTPHost, Int32 SMTPPort,
       string CredentialEmailId, string CredentialPassword, string strAttachment)
   {
       System.Net.Mail.MailMessage ResetPassMail = new System.Net.Mail.MailMessage();
       SmtpClient SmtpServer = new SmtpClient();
       ResetPassMail.To.Add(new MailAddress(ToEmailId));
       ResetPassMail.From = new MailAddress(FromEmailId, FromName);
       ResetPassMail.Sender = new MailAddress(SenderEmailId, SenderName);
       ResetPassMail.Subject = Subject;
       ResetPassMail.IsBodyHtml = true;
       ResetPassMail.Body = MailBody;
       ResetPassMail.Priority = System.Net.Mail.MailPriority.High;
       Attachment attach = new Attachment(strAttachment);
       ResetPassMail.Attachments.Add(attach);
       SmtpServer.Host = SMTPHost;
       SmtpServer.Port = SMTPPort;
       SmtpServer.Credentials = new NetworkCredential(CredentialEmailId, CredentialPassword);
       SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
       try
       {
           SmtpServer.Send(ResetPassMail);

           return true;
       }
       catch (Exception ex)
       {

           throw ex;
       }

   }
 
Share this answer
 
Comments
OPees 3-Feb-13 23:05pm    
Thanks Mahesh...!!
OPees 11-Feb-13 3:21am    
Hello Mahesh,
i got this Error
The remote certificate is invalid according to the validation procedure

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