Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im coded here:
C#
private void Send()
    {
        try
        {
            string Subject = "This is test mail using smtp settings",
            Body = "sad",
            ToEmail = txtEmail.Text.Trim();

            string SMTPUser = "eDMS.tanphu@gmail.com", SMTPPassword = "myPass";

            //Now instantiate a new instance of MailMessage
            MailMessage mail = new MailMessage();

            //set the sender address of the mail message
            mail.From = new MailAddress(SMTPUser, "iDOC");

            //set the recepient addresses of the mail message
            mail.To.Add(ToEmail);

            //set the subject of the mail message
            mail.Subject = Subject;

            //set the body of the mail message
            mail.Body = Body;

            //leave as it is even if you are not sending HTML message
            mail.IsBodyHtml = true;

            //set the priority of the mail message to normal
            mail.Priority = MailPriority.Normal;

            //instantiate a new instance of SmtpClient
            SmtpClient smtp = new SmtpClient();

            //if you are using your smtp server, then change your host like "smtp.yourdomain.com"
            smtp.Host = "smtp.gmail.com";

            //chnage your port for your host
            smtp.Port = 25; //or you can also use port# 587

            //provide smtp credentials to authenticate to your account
            smtp.Credentials = new System.Net.NetworkCredential(SMTPUser, SMTPPassword);
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            //if you are using secure authentication using SSL/TLS then "true" else "false"
            smtp.EnableSsl = true;

            smtp.Send(mail);
        }
        catch (SmtpException ex)
        {
        }
    }

Im used port 587
My code is not error but is not work. Any guess what to do?
Thanks
Posted
Comments
Animesh Datta 1-Jul-15 1:26am    
any error are you getting ?
Michael_Davies 1-Jul-15 1:30am    
Gmail uses SSL/TLS for smtp, use port 465 not 25.

SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587; //port should be 587.Try this port number once
 
Share this answer
 
Thanks all
I created another email, it worked
 
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