Friday, 10 August 2012

Send Mail From Application in c#


MailMessage message = new MailMessage();
message.From = new MailAddress(From);
            foreach (string address in To)
                message.To.Add(address);
            if (null != bcc)
                foreach (string address in bcc)
                {
                    message.Bcc.Add(address);
                }

            message.Subject = Subject;
            message.Body = Body;
            message.IsBodyHtml = true;

            SmtpClient smtpClient = new SmtpClient();
            smtpClient.UseDefaultCredentials = false;
            smtpClient.Host = "smptp.gmail.com";
            smtpClient.Port = 695;//port number
            smtpClient.EnableSsl = true;
            //if (false)
            //    smtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
            //else
               smtpClient.Credentials = new NetworkCredential("admin@domain.com", "password");
            smtpClient.Send(message);
}

No comments:

Post a Comment