Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Web Config:
 
<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
 
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 30-Jan-13 2:28am
OPees2.5K
Edited 30-Jan-13 3:40am
RyanDev136.3K
v3
Comments
ryanb31 at 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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

hi dear,
Please use below secure mail function
 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;
        }
       
    }
  Permalink  
Comments
OPees at 3-Feb-13 23:05pm
   
Thanks Mahesh...!!
OPees at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,963
1 OriginalGriff 6,726
2 Peter Leow 4,232
3 Zoltán Zörgő 3,769
4 Richard MacCutchan 2,558


Advertise | Privacy | Mobile
Web02 | 2.8.150123.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100