Send Email in ASP.net is a web-based system that has been created and designed to send email via the Internet.
Further, Sending email is a typical operation in almost any online application for a variety of reasons.
In our everyday development, we need to integrate mail functionality into our project so that we may send e-mails to customers or other people on our website.
About the Project:
Send Email in ASP.net is a web-based application with a front-end written in ASP.NET C# using Visual Studio and a back-end database written in SQL Server.
Send email to any internet email address and send SMS to any mobile number with the Email and SMS Server web application.
We provide a Send Email from ASP.net for all users. Users must first register and then check in to the system.
Once logged in, users can send emails within our system as well as to other internet email addresses.
Our system provides Inbox, Send Item, Trash Mail, and Contact List functionality to all users. For sending email over the internet, we use the SMTP protocol.
The System.Net.Mail Namespace is provided by the.NET development platform to send electronic mail using ASP.net.
The System.Net.Mail namespace contains classes used to send electronic mail to a Simple Mail Transfer Protocol (SMTP) server for delivery.
I will be using SmtpClient and MailMessage to demonstrate how we can create web applications to send email by using the Simple Mail Transfer Protocol (SMTP).
SmtpClient Class
The SmtpClient Class belongs to the System.Net.Mail namespace.
The SmtpClient class Allowsapplications to send email by using the Simple Mail Transfer Protocol (SMTP).
The SmtpClient class is used to send email to an SMTP server for delivery. To construct and send an email message by using SmtpClient, you must specify the following information,
- The SMTP host server and port that can be used to send email.
- Credentials property for authentication, if required by the SMTP server.
- The email address of the sender.
- The email address or addresses of the recipients.
- The message content.
The SmtpClient class constructors along with their overloads are as follows,
SmtpClient Class | Meaning |
SmtpClient() | Initializes a new instance of the SmtpClient class by using configuration file settings. |
SmtpClient(String) | Initializes a new instance of the SmtpClient class that sends email by using the specified SMTP server. |
SmtpClient(String, Int32) | Initializes a new instance of the SmtpClient class that sends email by using the specified SMTP server and port. |
Some of the widely used properties of SmtpClient class are as follows,
Credentials | Gets or sets the credentials used to authenticate the sender. |
DeliveryMethod | Specifies how outgoing email messages will be handled. |
EnableSsl | Specify whether the SmtpClient uses Secure Sockets Layer (SSL) to encrypt the connection. |
Host | Gets or sets the name or IP address of the host used for SMTP transactions. |
Port | Gets or sets the port used for SMTP transactions. |
UseDefaultCredentials | Gets or sets a Boolean value that controls whether the DefaultCredentials are sent with requests. |
Some of the widely used methods of SmtpClient class are as follows,
Send(MailMessage) | Sends the specified message to an SMTP server for delivery. |
Send(String, String, String, String) | Sends the specified email message to an SMTP server for delivery. The message sender, recipients, subject, and message body are specified using String objects. |
MailMessage Class
MailMessage Class represents an email message that can be sent using SmtpClient class.
Instances of the MailMessage class are used to construct email messages that are transmitted to an SMTP server for delivery using the SmtpClient class.
The sender, recipient, subject, and body of an email message may be specified as parameters when a MailMessage is used to initialize a MailMessage object.
These parameters may also be set or accessed using properties on the MailMessage object.
Following are the properties of MailMessage class,
MailMessage Class | Meaning |
To | Gets the address collection that contains the recipients of this email message. |
From | Gets or sets from address for this email message. |
Subject | Gets or sets the subject line for this email message. |
Body | Gets or sets the message body. |
The MailMessage class constructors along with their overloads are as follows,
MailMessage() | Initializes an empty instance of the MailMessage class. |
MailMessage(MailAddress, MailAddress) | Initializes a new instance of the MailMessage class by using the specified MailAddress class objects. |
MailMessage(String, String) | Initializes a new instance of the MailMessage class by using the specified String class objects. |
MailMessage(String, String, String, String) | Initializes a new instance of the MailMessage class. |
Attachment Class
Represents an attachment to an email.
The Attachment class is used with the MailMessage class. All messages include a Body, which contains the content of the message.
In addition to the body, you might want to send additional files. These are sent as attachments and are represented as Attachment instances.
To add an attachment to a mail message, add it to the MailMessage.Attachments collection.
Attachment content can be a String, Stream, or file name. You can specify the content in an attachment by using any of the Attachment constructors.
The Attachment class constructors along with their overloads are as follows,
Attachment Class | Meaning |
Attachment(Stream, ContentType) | Initializes a new instance of the Attachment class with the specified stream and content type. |
Attachment(Stream, String) | Initializes a new instance of the Attachment class with the specified stream and name. |
Attachment(Stream, String, String) | Initializes a new instance of the Attachment class with the specified stream, name, and MIME type information. |
Attachment(String) | Initializes a new instance of the Attachment class with the specified content string. |
Attachment(String, ContentType) | Initializes a new instance of the Attachment class with the specified content string and ContentType. |
Some of the widely used properties of the Attachment class are as follows,
ContentId | Gets or sets the MIME content ID for this attachment. |
ContentStream | Gets the content stream of this attachment. |
ContentType | Gets the content type of this attachment. |
Name | Gets or sets the MIME content type name value in the content type associated with this attachment. |
ContentDisposition | Gets the MIME content disposition for this attachment. |
Some of the widely used methods of Attachment class are as follows,
CreateAttachmentFromString(String, ContentType) | Creates a mail attachment using the content from the specified string, and the specified ContentType. |
CreateAttachmentFromString(String, String) | Creates a mail attachment using the content from the specified string, and the specified MIME content type name. |
CreateAttachmentFromString(String, String, Encoding, String) | Creates a mail attachment using the content from the specified string, the specified MIME content type name, character encoding, and MIME header information for the attachment. |
Send Email in ASP.net with C#: Project Details and Technology
Project Title: | Send Email in ASP.net and C# with Source Code |
---|---|
Abstract : | Send Email in ASP.net is a form of electronic commerce which allows consumers to directly buy goods or services from a seller over the Internet using a web browser or a mobile app. |
Project Type: | Web App |
Technology : | ASP.net Visual Studio 2022 with C# Language |
Database : | SQL-Server 2021 |
Steps on How To Send Email :
Time needed: 5 minutes
Send Email in ASP.net and C# with Source Code
- Step 1: Download Source Code
First, find the downloadable source code below and click to start downloading the source code file.
- Step 2: Extract File
Next, after finished to download the file, go to the file location, right-click the file, and click extract.
- Step 3: Open Visual Studio
Next, open Microsoft Visual Studio, click the file, open website, and open the extracted folder.
- Step 4: Run Project
Last, click the run button to start executing the project
Download the Source Code below!
Summary
This Send Email in ASP.net Core also has an SMS module, which allows users to send text messages to any registered user’s phone number using our system.
The website is mostly used to send email and SMS to mobile devices.
Related Article
Inquiries
If you have any questions or suggestions about Send Email in ASP.net and C# with Source Code, please feel free to leave a comment below.