Click here to Skip to main content
14,601,061 members
Rate this:
Please Sign up or sign in to vote.
See more:
Im coded here:
private void Send()
            string Subject = "This is test mail using smtp settings",
            Body = "sad",
            ToEmail = txtEmail.Text.Trim();

            string SMTPUser = "", 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

            //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.Host = "";

            //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;

        catch (SmtpException ex)

Im used port 587
My code is not error but is not work. Any guess what to do?
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.
Rate this:
Please Sign up or sign in to vote.

Solution 1

SmtpClient smtp = new SmtpClient();
smtp.Host = "";
smtp.Port = 587; //port should be 587.Try this port number once
Rate this:
Please Sign up or sign in to vote.

Solution 2

Thanks all
I created another email, it worked

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100