Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am using asp.net 3.5 version and trying to send email from my application. I am using following codes:
C#
MailMessage Mail = new MailMessage();
Mail.From = new System.Net.Mail.MailAddress("username");
Mail.To.Add("recipient mail id");
Mail.Subject = TextBox3.Text;
Mail.Body = TextBox4.Text;
Mail.Priority = MailPriority.High;

SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.Credentials = new System.Net.NetworkCredential("username", "password");
smtp.EnableSsl = true;
smtp.Send(Mail);


But I am getting following error:
The requested address is not valid in its context 74.125.47.109:25

Can anyone send me the proper code to resolve this error.
Posted
Updated 27-Oct-10 21:29pm
v2
Comments
Dalek Dave 28-Oct-10 3:29am    
Minor Edit for Grammar.

Is the port open? Firewall permissions in place?
Further make sure you have configured 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>

If needed, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]
If needed, there are lots of article on this very site on how to send emails.
 
Share this answer
 
 
Share this answer
 
I am getting error on adding following code to web.config
XML
<system.net>
    <mailSettings>
      <smtp from="abc@somedomain.com">
        <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
      </smtp>
    </mailSettings>
 </system.net>


Error is :
The requested address is not valid in its context 74.125.65.109:25

Please let me know the solution for this.
 
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