Send Email in  

by ne on 2021-09-29 under C#/Php

For sending emails in with c#.

first add the following namespace :-

using System.Net.Mail

and than you have to write following lines of code on button click event:-

    MailMessage message = new MailMessage();
    message.From = new MailAddress("fromusername@DomainName");
    message.To.Add(new MailAddress("tousername@DomainName"));
    message.CC.Add(new MailAddress("ccusername@DomainName"));
    message.Subject = "Subject";
    message.Body = "Content";
    SmtpClient client = new SmtpClient();

in web.config you have to add following section:-

            <smtp from="username@DomainName">
                <network host="SMTPServerName" port="25" userName="username" password="secret" defaultCredentials="true" />