I'm very new to the ASP.NET C# area. I'm planning to send a mail through ASP.NET C# and this is the SMTP address from my ISP:
smtp-proxy.tm.net.my
Below is what I tried to do, but failed.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="SendMail" %>
<html>
<head id="Head1" runat="server"><title>Email Test Page</title></head>
<body>
<form id="form1" runat="server">
Message to: <asp:TextBox ID="txtTo" runat="server" /><br>
Message from: <asp:TextBox ID="txtFrom" runat="server" /><br>
Subject: <asp:TextBox ID="txtSubject" runat="server" /><br>
Message Body:<br>
<asp:TextBox ID="txtBody" runat="server" Height="171px" TextMode="MultiLine" Width="270px" /><br>
<asp:Button ID="Btn_SendMail" runat="server" onclick="Btn_SendMail_Click" Text="Send Email" /><br>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
And below is my code-behind:
using System;
using System.Web.UI.WebControls;
using System.Net.Mail;
public partial class SendMail : System.Web.UI.Page
{
protected void Btn_SendMail_Click(object sender, EventArgs e)
{
MailMessage mailObj = new MailMessage(
txtFrom.Text, txtTo.Text, txtSubject.Text, txtBody.Text);
SmtpClient SMTPServer = new SmtpClient("127.0.0.1");
try
{
SMTPServer.Send(mailObj);
}
catch (Exception ex)
{
Label1.Text = ex.ToString();
}
}
}
PS: I'm sorry that I couldn't understand the receiver/sender SMTP concept, and so I am trying to understand the whole concept from here.
Check this out .... it works
http://www.aspnettutorials.com/tutorials/email/email-aspnet2-csharp/
You can try this using hotmail like this:-
If you want to generate your email bodies in razor, you can use Mailzory. Also, you can download the nuget package from here.
This just works perfectly for me.
You can try MailKit
Just go through the below code.