I want to send a dummy email from my server in .NET to my mail .
I am just sending mail without manipulation : Please let me know where I am going wrong . I have written my code as below :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SendingEmail.aspx.cs" Inherits="experiments_asp_SendingEmail" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<h2>Send e-mail to someone@example.com:</h2>
<asp:Button Text="Submit" OnClick="sendMail" runat="server"/>
</form>
</body>
</html>
my .Net Code is shown as below :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
public partial class experiments_asp_SendingEmail : System.Web.UI.Page
{
protected void sendMail(object sender, EventArgs e)
{
Console.Write("came here");
CreateTestMessage2("my college server"); //
}
public static void CreateTestMessage2(string server)
{
string to = "xyz@gmail.com";
string from = "xyz@gmail.com";
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the new SMTP client.";
message.Body = @"Using this new feature, you can send an e-mail message from an application very easily.";
SmtpClient client = new SmtpClient(server);
client.UseDefaultCredentials = true;
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in CreateTestMessage2(): {0}",
ex.ToString());
}
}
}
Please let me know if any issues in this code , Do i need to add anything extra.
I am not getting any error when i click on submit.
Expectation : to send a dummy mail . Please note I am new to <