Wednesday, September 20, 2017

Send Email using SmtpClient C# ASP.Net

string MessageBody;

        MailAddress mfrom = new MailAddress("ControlsTeam@xxxxxxxx.com");
        MailAddress mTo = new MailAddress(getemail);
        //MailAddress mcc = new MailAddress(getemail);
        string EmailSubject = "This Control ID:" + ctrlID + "has been Update";
        MailMessage message = new MailMessage();
        message.From = mfrom;
        message.To.Add(mTo);
        //message.CC.Add(mcc);
        if (string.Equals(mfrom.ToString().ToUpper().ToString(), mTo.ToString().ToUpper().ToString()))
        {
            MessageBody = "This control ID" + ctrlID + "has been changed";
            EmailSubject = TextBox1.Text + "Test Email";
        }
        message.Subject = EmailSubject;
        message.Body = "This is the test Email for Control Update"; ;
        message.IsBodyHtml = true;


        SmtpClient client = new SmtpClient("xxxxx.xxxx.xxxx", 25);//server name
        // Credentials are necessary if the server requires the client
        // to authenticate before it will send e-mail on the client's behalf.
        client.UseDefaultCredentials = true;
        message.IsBodyHtml = true;

        client.Send(message);

No comments: