11
Answers

email in C#

Ask a question
kritika Rana

kritika Rana

11y
999
1
Hi

I have some code which sends email to specified person using gmail account but I want to send it with some other account .How to configure the code with other account.

The code is as below:'

 private void SendMail(string fileContent)
        {
            MailMessage mailMessage = new MailMessage();
            mailMessage.From = new MailAddress("[email protected]", "Kritika");
           // mailMessage.To.Add("[email protected]");
           // mailMessage.To.Add("[email protected]");
            mailMessage.To.Add("[email protected]");
            mailMessage.Subject = "Test Email";

            mailMessage.IsBodyHtml = true;
            mailMessage.Body = fileContent + "<br/> <br/> <br/>";
            using (SmtpClient mailbox = new SmtpClient("smtp.gamil.com", 587))
            {
                mailbox.Credentials = new NetworkCredential("[email protected]", "paswd");
                mailbox.EnableSsl = true;
                mailbox.Send(mailMessage);
            }

        }

what has to written in place of highlighted text to send email from [email protected] to specified person.

Answers (11)