Sending E-mail from IIS SMTP
To send e-mail from an Asp.Net
application using the System.Net.Mail, you must configure Simple Mail Transfer
Protocol (SMTP) e-mail. Mail can be delivered immediately, or it can be
delivered to a file location on disk where it is configured.
The procedures for configuring SMTP e-mail can be performed at the
following levels in Internet Information Services (IIS):
- IIS Server
- Asp.Net Application
- Physical and virtual directories
Install SMTP
Click on the below link to understand how to Configure or Install IIS Server
Following Steps to Configure SMTP
E-Mail for a Web Application
Step-1
Create Asp.Net application for
sending E-mail
1. Run Visual
Studio as Administrator
2. Click on FILE
-> NEW -> Web site.
3. Click
Templates as Visual C#, .Net framework, web location as HTTP
4. Type project
name as http://localhost/SendingEmailByIIS
5. Click OK
Step-2
Right click on the project-> Add
-> Add New Item -> Select Web form ->Click Add button
Step-3
In Default.aspx file copy and paste below code
<table style="font-family: Arial,'Segoe UI';">
<tr>
<td colspan="3">
<span align="left">
<asp:Image ID="imgMail" runat="server" ImageUrl="~/Image/mail.png" Width="50px"
Height="30px" />
</span>
<span style="font-size: 20px; margin-top: -5px">Sending Email through SMTP IIS
</span>
</td>
</tr>
<tr>
<td>From</td>
<td>:</td>
<td>
<asp:TextBox ID="txtFrom" runat="server" Width="300"></asp:TextBox>
</td>
</tr>
<tr>
<td>To</td>
<td>:</td>
<td>
<asp:TextBox ID="txtTo" runat="server" Width="300"></asp:TextBox>
</td>
</tr>
<tr>
<td>Subject</td>
<td>:</td>
<td>
<asp:TextBox ID="txtSubject" runat="server" Width="300"></asp:TextBox>
</td>
</tr>
<tr>
<td>Message</td>
<td>:</td>
<td>
<asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" Rows="5"
Columns="40"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3"
align="Right">
<asp:Button ID="btnSend" runat="server" Text="Send mail" OnClick="btnSend_Click" BackColor="#009999" ForeColor="White" Font-Bold="true"
BorderColor="#009999" />
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="lblStatus" runat="server" />
</td>
</tr>
</table>
Step-4
In Default.aspx.cs file copy and paste below code
using System.Net.Mail;
protected void btnSend_Click(object
sender, EventArgs e)
{
try
{
string
from = txtFrom.Text.Trim();
string
to = txtTo.Text.Trim();
string
subject = txtSubject.Text.Trim();
string
message = txtMessage.Text.Trim();
SmtpClient
objSmtpClient = new SmtpClient();
objSmtpClient.Host = "localhost";
objSmtpClient.Port =
25;
objSmtpClient.Send(from, to, subject, message);
lblStatus.Text = "<b style='color:green'>Email has been
sent successfully!!!</b>";
}
catch
(SmtpException ex) { lblStatus.Text = "<b style='color:red'>" + ex.Message + "</b>"; }
}
Step-5
Open Web.Config and notice the code
Step-6
·
Click on the Windows Logo + R.
·
Type INETMGR in the Run window.
·
Click ok.
Step-7
Now Select the Project that you
have created.
Step-8
After select your project, Double
click on the SMTP E-mail and type as
follows
- Click on the Deliver e-mail to SMTP server
- Enter in below SMTP Server textbox as “localhost”
- Click on the Use localhost checkbox
- Port: 25
- Authentication Settings- Not required
- Click on the browse button to select the pickup directory where you want to receive the E-mail
- Now click on Apply from the right side of Action section
Step-9
Click on Yes to All button and
look at the changes in the Web.Config file
Step-10
Sending E-mail from IIS SMTP
Reviewed by Revanth
on
February 06, 2016
Rating:
I do not have such a SMTP E-mail option on my IIS
ReplyDeleteIn such a case reinstall the IIS and try it.
ReplyDeleteFor installing and configuring IIS in local machine watch below videos.
Watch: https://www.youtube.com/playlist?list=PLG_QjCllP5VtMQddPw59oG7UFyfdVLxps
SUBSCRIBE: https://www.youtube.com/dotnetrevanth
Stay tuned have a nice day :)
I didnt received any email ..its not working
ReplyDeleteThis is amazing and awesome , thanks for sharing
ReplyDelete.Net Online Training Bangalore
ReplyDeletevery nice article you shared.
if you want to know the technologies updates,visit below site.
dot net and latest technologies Tutorials
Very nice article!
ReplyDeleteThanks.
Ravi (DotNetTec)
It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
ReplyDeleteArtificial Intelligence Course
Java Course
AWS Course
Machine Learning Course
Data Science Course
DevOps Course
Even though many people have been writing e-mails for a few years now, you would be amazed at some of the pure gibberish that arrives in Aolmail on a regular basis. This article tells people how they can at least observe some basic civility when composing and sending their e-mails.
ReplyDeleteYour support means a lot to me! See this profile for more details CPS Test. Practicing regularly can help you achieve a higher clicks per second rate.
ReplyDelete