Click here to Skip to main content
15,890,946 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi All,

I am using VS2008, Asp.Net3.5, Win7.
How can set(configure) SMTP in Win7.
I am getting error (failure sending message) from smtpClient.Send(message).
I have doubt for smtp, i think i am not getting understand how to set smtp server.
so plz give me step by step idea for setting smtp server that's it work.

I am using this code below.
SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();
        try
        {
            MailAddress fromAddress = new MailAddress("mukeshpanth@gmail.com", "mukesh"); //from@site.com //Nameofsendingperson
            message.From = fromAddress;//here you can set address
            message.To.Add("mukeshpanth@yahoo.com");//here you can add multiple to  //to@site.com
            message.Subject = "Feedback";//subject of email 
            message.CC.Add("mukeshpanth@gmail.com");//ccing the same email to other email address
            message.Bcc.Add(new MailAddress("mukesh061984@gmail.com"));//here you can add bcc address 
            message.IsBodyHtml = false;//To determine email body is html or not
            message.Body = @"Plain or HTML Text";
            smtpClient.Send(message);
        }
        catch (Exception ex)
        {
            //throw exception here you can write code to handle exception here
            //Failure sending mail
        }

And I am using this code in web.config file.
host="localhost" port="25" in web.config file inside system.net tag
<system.net>  
<mailsettings>  
<smtp deliverymethod="Network"> 
<network host="localhost" port="25" defaultcredentials="true" />     
</smtp>       
</mailsettings>
</system.net>

help will be greatly appricated .......
Thanks
mukesh
Posted
Updated 1-Aug-11 1:28am
v4

1 solution

for SmtpClient smtpClient = new SmtpClient();
set the next smtpClient properties:
- Host (is servername)
- Port (mostly value 25)
 
Share this answer
 
Comments
mukesh_panth 1-Aug-11 7:17am    
hi,
I am using this code for web.confing file.
<system.net> <mailsettings> <smtp deliverymethod="Network"> <network host="localhost" port="25" defaultcredentials="true">
Herman<T>.Instance 1-Aug-11 7:25am    
how you have set this up in the web.config?

I have:

system.net>
mailsettings>
smtp deliverymethod="Network" from="youremailaddresshere">
network host="smtpserveraddresshere" port="25" defaultcredentials="true">
/network>
/mailsettings>
Herman<T>.Instance 1-Aug-11 7:33am    
I am missing the '<' sign at the beginning of each line
mukesh_panth 1-Aug-11 7:46am    
ya, i am using this follow details in the system.net tag. but i am getting error from the smtpclient.send(msg). smtpserveraddress means my localhost, right.
Herman<T>.Instance 1-Aug-11 7:53am    
if that is the smtp server than that is right. I guess the smtp server is a machine in the network with maybe an IP address. WHich mail client do you use for your email. FInd the address of the smtp server in the settings and use that server for sending mail.
otherwise:
what operating system do you use on your localhost? You might set up a smtp server

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