Click here to Skip to main content
15,902,276 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Dear All,

I tried many permutations and combinations for sending a mail from ASP.

But the result is still negative. There is no error but there is no mail in the inbox.

code is as follows.
protected void Button1_Click(object sender, EventArgs e)
    {
        MailMessage message = new MailMessage();
        SmtpClient smtpClient = new SmtpClient();
        
        smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

        try
        {
            MailAddress fromAddress = new MailAddress(Textbox2.Text, TextBox1.Text);
            

            //Default port will be 25

            smtpClient.Port = 25;
            message.From = fromAddress;

           


            message.To.Add("????@gmail.com");
           
            message.IsBodyHtml = false;
            message.Body = TextBox3.Text;
            message.Subject = "test";
          
            smtpClient.Send(message);
            

            
            Label3.Text = "Email Sent";


        }
        catch(Exception ex)

        {
            Label3.Text = "Sending Failed" + ex.Message;


        }


    }



I have made the following changes in web.config.

XML
<system.net>
    <mailSettings>
      
        <network host="192.168.1.33" port="25" userName="username" password="password" defaultCredentials="true" />

    </mailSettings>


Can anybody let me know th exact meaning of the host or the SMTP Server here, it is "smtp.gmail.com", or "localhost", or "my IP address".

I guess I am not specifying this parameter correctly, thats y i am facing the problem.

Also I wanted to know whether that user name and password should be provided or no ???

Kindly assist.

Many Thanks in Advance.
Mukund G Kallapur
Posted
Updated 19-Sep-10 5:28am
v3
Comments
Anthony Mushrow 19-Sep-10 11:29am    
You need to be careful about posting your email on the internet, or you inbox will be filled with thousands of spam emails.

1 solution

Well, when I send a mail I use localhost instead of any specific IP address and I don't specify a user name or password. I'm not sure if the name and password matter since your using DefaultCredetials though.

But also looking at msdn you may need adjust your web.config so that the actuall settings are in an smpt node:

XML
<configuration>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="network">
        <network
          host="localhost"
          port="25"
          defaultCredentials="true"
        />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>

http://msdn.microsoft.com/en-us/library/w355a94k.asp[^]

If you want to actually send your email through Gmail then I believe you can specify smpt.gmail.com as the server (the port should stay on 25) but you'd then need to give your gmail username and password and not use DefaultCredentials
 
Share this answer
 
v3
Comments
Mukund Kallapur 19-Sep-10 15:31pm    
Tried this also...but I guess there is no solution to my problem... :(

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