How to send email in ASP NET C

0 votes

I'm a complete novice when it comes to ASP.NET C#. I'm going to send a mail using ASP.NET C#, and this is my ISP's SMTP address:

smtp-proxy.tm.net.my

This is what I did 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 this is the code

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();
        }
    }
}

I am new to this so any ideas for a solution?

Jun 11, 2022 in C# by krishna
• 2,820 points
584 views

1 answer to this question.

0 votes

You can try this using Hotmail like this

MailMessage o = new MailMessage("From", "To","Subject", "Body");
NetworkCredential netCred= new NetworkCredential("Sender Email","Sender Password");
SmtpClient smtpobj= new SmtpClient("smtp.live.com", 587); 
smtpobj.EnableSsl = true;
smtpobj.Credentials = netCred;
smtpobj.Send(o);
answered Jun 14, 2022 by krishna
• 2,820 points

Related Questions In C#

0 votes
1 answer

How to find the extension of a file in C#

Go to here https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getextension?redirectedfrom=MSDN&view=net-6.0#System_IO_Path_GetExtension_System_String_ string myFilePath = @"C:\MyFile.txt"; string ext ...READ MORE

answered Jun 21, 2022 in C# by jyoti
• 1,240 points
322 views
0 votes
0 answers

How to create dependency injection for ASP.NET MVC 5

It's simple to create Dependency Injection using ...READ MORE

Jun 11, 2022 in C# by pranav
• 2,590 points
321 views
0 votes
0 answers

How do I turn a C# object into a JSON string in .NET?

The following is my classes class MyDate { ...READ MORE

Sep 26, 2022 in C# by krishna
• 2,820 points
241 views
0 votes
1 answer

What is the best C# to VB.net converter

Telerik has a solid SharpDevelop-based converter that ...READ MORE

answered May 30, 2022 in C# by rajiv
• 1,620 points
1,289 views
0 votes
1 answer

Authenticate on an ASP.Net Forms Authorization website from a console app

Essentially, we need to record a regular ...READ MORE

answered Sep 20, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
587 views
0 votes
1 answer

Writing SEO friendly url gets infinite loop asp.net

you should know that regex avoid cases ...READ MORE

answered Feb 11, 2022 in Others by narikkadan
• 63,420 points
614 views
0 votes
0 answers

How to get Bitcoin value for corresponding USD value in ASP.NET C#?

I want to get the Bitcoin value ...READ MORE

Mar 1, 2022 in Blockchain by Soham
• 9,700 points
651 views
0 votes
0 answers

The request was aborted: Could not create SSL/TLS secure channel

When I connect to an  HTTPS server ...READ MORE

May 1, 2022 in Other DevOps Questions by Kichu
• 19,050 points
1,733 views
0 votes
1 answer

How do I turn a C# object into a JSON string in .NET

Newtonsoft.json can be used to accomplish this. ...READ MORE

answered Jun 13, 2022 in C# by krishna
• 2,820 points
341 views
0 votes
1 answer

How to practice a language like C#

I believe you should begin with personal ...READ MORE

answered Jun 13, 2022 in C# by krishna
• 2,820 points
235 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP