Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, i am yogesh and i have a problem in sending email using free smtp server.
I have windows 7 prof...(os).
windows7 has not haveing default smtp server installed... so what i have to do please
give me example of step by step installing smtp server as i have tried many options
i also used gmail server but failed. I also found that windows 7 no longer support
smtp server so what to do... my code i just tried using gmail server is as follows..
C#
string from = "imyogesh@mail.com"; // this is my gmail account
              string to = "imyogesh@mail.com";

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
 mail.To.Add(to);
 mail.From = new MailAddress(from, "One Ghost" , System.Text.Encoding.UTF8);
mail.Subject = "This is a test mail" ;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = "This is Email Body Text";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true ;
mail.Priority = MailPriority.High;

SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(from, "PASSWORD");

client.Port = 587; // Gmail works on this port
client.Host = "smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layer
       try
        {
            client.Send(mail);
        }
        catch (Exception ex) 
        {
            Exception ex2 = ex;
            string errorMessage = string.Empty; 
            while (ex2 != null)
            {
                errorMessage += ex2.ToString();
                ex2 = ex2.InnerException;
            }
   HttpContext.Current.Response.Write(errorMessage );
        }  

what is wrong with this code.
i have installed iis7... and i don't know how to install smtp serve..
please help me i m trying since 5 day. i need to test my application for sending emails.
As windows 7 is not supporting smtp server what i have to do.
with this code iam getting error.
/*
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at ADVANCED_FORUM.email.Page_Load(Object sender, EventArgs e) in D:\DOTNET\web\ADVANCED_FORUM\ADVANCED_FORUM\email.aspx.cs:line 84
*/

pleas suggest me solution....
Posted
Updated 12-Jan-12 19:10pm
v2

 
Share this answer
 
Comments
NandaKumer 13-Jan-12 0:50am    
good links
yogesh a sharma 13-Jan-12 10:08am    
thanks i got my answer with ur 1st link thanks very much
07navneet 25-Jan-12 7:01am    
dude, please paste your final solution. please!!
hi yogi,

you can try this
C#
MailAddress mailfrom = new MailAddress ( "from@gmail.com" );
           MailAddress mailto = new MailAddress ( "to@gmail.com" );
           MailMessage newmsg = new MailMessage ( mailfrom, mailto );

           newmsg.Subject = "Subject of Email";
           newmsg.Body = "Body(message) of email";

           ////For File Attachment, more file can also be attached

           Attachment att = new Attachment ( "G:\\code.txt" );
           newmsg.Attachments.Add ( att );

           SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 );
           smtps.UseDefaultCredentials = false;
           smtps.Credentials = new NetworkCredential ( "urmail", "password" );
           smtps.EnableSsl = true;
           smtps.Send ( newmsg );

i hope this will help you
 
Share this answer
 
v2
Comments
yogesh a sharma 13-Jan-12 7:20am    
thanks sir but using your code i m getting error as follows---
System.Net.Mail.SmtpException was unhandled by user code
Message=The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
still need help
Bojjaiah 27-Mar-14 5:23am    
I think you are given wrong credentials. Please check your account username & password.
Shashi kant Tiwary 14-Jan-12 22:15pm    
Thanks for giving this code to me.
Bojjaiah 27-Mar-14 5:23am    
You are welcome :)
Member 9129971 24-Mar-14 12:49pm    
using your code i m getting error similiar error---
System.Net.Mail.SmtpException was unhandled by user code
Message=The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
plz help how to fix it

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