Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
i want to know how can i send email or read my emails by c# without using outolook or exchange web service? i should give my mail address and password and if they were correct let me send/read my mails and if my mail address or password were not correct doesn't let me do any thing.codes should be in C#.
i searched on the internet but i could not find a good thing. they were fake mail codes or creating mail server codes. i need to log in to yahoomail or gmail by c#.
Posted
Comments
[no name] 20-May-14 10:26am    
You need to improve your search skills then. This exact information is all over the internet, http://www.bing.com/search?q=c%23+gmail returns over 3 million results for you to look at.

1 solution

Try this, hope it will help you.

for domain, change the port no., n check.

public void SendEmails(string ToEmail, string EmailSub, string EmailBody)
        {
            #region

            MailMessage mailer = new MailMessage();

            System.Net.NetworkCredential smtpauth = new System.Net.NetworkCredential();
            smtpauth.UserName = "npsproject300@gmail.com";
            smtpauth.Password = "project2013";

            SmtpClient smtp = new SmtpClient();
            smtp.UseDefaultCredentials = false;
            smtp.Host = "smtp.gmail.com";  //SMTP SERVER
            smtp.Credentials = smtpauth;
            smtp.Port = 587; // port no# 465 is gmail, 25 was domain dg.sa
            smtp.EnableSsl = true;

            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

            mailer.From = new MailAddress("npsproject300@gmail.com"); // Change it
            mailer.Subject = EmailSub;
            mailer.Priority = MailPriority.High;


            mailer.Body = EmailBody; // this is Body



            mailer.IsBodyHtml = true; // it is set to HTML 
            if (ToEmail.Contains(";"))
            {
                try
                {
                    string[] emails_ = ToEmail.Split(';');
                    for (int i = 0; i < emails_.Length; i++)
                    {
                        mailer.To.Add(new MailAddress(emails_[i]));
                    }
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                mailer.To.Add(new MailAddress(ToEmail)); //Receiver's Email address
            }

            smtp.Send(mailer);
            #endregion
<pre lang="text">


}

 
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