Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am facing a problem and I am not able to understand, please help me.

I am writing a Sending Mail code but I am not able send a mail.
I don't know where is the problem



C#
// Create a Mail Address Type Object for From Email
                 MailAddress sFrom = new MailAddress("xyz@mail.yahoo.com", "New Message");

               // Create a Mail Address Type Object for To Email
                MailAddress sTo = new MailAddress("abc@cherisys.com");

                // Create a Mail Message Type Object for Email and assign values to various properties, like subject, body, mail type.
                MailMessage MyMail = new MailMessage(sFrom, sTo);
                MyMail.Subject = "Subject Text";
                MyMail.Body = "Body Text";
                MyMail.IsBodyHtml = true;
                MyMail.BodyEncoding = Encoding.UTF8;

                //Create a SMTP client type object, Protocol responsible to send emails. And add the address of your email SMTP. Example of Yahoo added.

                SmtpClient SmtpMail = new SmtpClient("smtp.mail.yahoo.com");
                SmtpMail.EnableSsl = true;

                // Decline default credentials and add yours. Your Email (From Email) & Password.
                SmtpMail.UseDefaultCredentials = false;
                SmtpMail.Credentials = new System.Net.NetworkCredential("xyz@mail.yahoo.com", "xyzpassword");
    
                // Now send email
                try
                {
                    SmtpMail.Send(MyMail);
                }
                catch (Exception o) { }
Posted
Updated 25-Jan-12 21:48pm
v2
Comments
Dalek Dave 26-Jan-12 3:49am    
Edited for Grammar, Syntax, Readability and Code Block.
thatraja 26-Jan-12 4:05am    
What's the error? why there's no code(for handling exception) in catch block?

 
Share this answer
 
Comments
Uday P.Singh 26-Jan-12 4:23am    
5+
 
Share this answer
 
Comments
Uday P.Singh 26-Jan-12 4:23am    
5!
Please check the following url,

Send mail using Google Apps

If you are sending email from gmail or google apps than all sent email would be store in the sent items of the gmail.
Hope this may help you...
 
Share this answer
 
v2

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