Let’s see how to send Email with BCC and attachment with ASP.NET.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.Net.Mail;
using System.IO;
public partial class sendmail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnmail_Click(object sender, EventArgs e)
{
{
string mAttach;
MailMessage msg = new MailMessage();
MailAddress ma = new MailAddress("from email-ID", "Name");
msg.From = ma;
if (txtTo.Text.Trim().Length != 0)
{
msg.To.Add(txtTo.Text);
}
if (txtBcc.Text.Trim().Length != 0)
{
msg.Bcc.Add(txtBcc.Text);
}
if (txtCC.Text.Trim().Length != 0)
{
msg.CC.Add(txtCC.Text);
}
Attachment at = new Attachment(FileResume.PostedFile.InputStream, FileResume.FileName);
msg.Attachments.Add(at);
msg.Subject = txtSubject.Text;
msg.Body = txtMessage.Text;
try
{
SmtpClient smpt = new SmtpClient();
smpt.Host = "Your Server Name";
smpt.Send(msg);
}
catch (Exception ex)
{
}
}
}
}
The System.Net.Mail namespace is the one which contains the classes used to send electronic mail to a Simple Mail Transfer Protocol (SMTP) server for delivery.
SmtpClient class is the one which allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP).
Mail Message is the one that represents an e-mail message that can be sent using the SmtpClient class.
Attachment is the class that represents an attachment to an e-mail.