.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

email using dot net

Posted By: mamallan     Posted Date: January 03, 2011    Points:2   Category :C#
i entered these but i didnt got output
<%@ Page Language="C#" %>
<%@ Import NameSpace="System.Web.Mail" %>
<%@ Import Namespace="System.Web.Mail.SmtpMail" %>

<script runat="server">
protected void Page_Load(Object Sender, EventArgs e)
Message.Text = "Sending Email using ASP.NET";

protected void Send_Email(Object Sender, EventArgs e)

MailMessage mail = new MailMessage();

mail.To = Request.Form["to"];
mail.From = Request.Form["from"];

mail.BodyFormat = MailFormat.Text;
mail.BodyFormat = MailFormat.Html;

mail.Subject = Request.Form["subject"];
mail.Body = Request.Form["body"];


Message.Text = "Message Sent...<br><br>" +
"<a href=\"default.aspx\">Go Back</a>";

<title>Sending Emails using ASP.NET ( Part I )</title>
a { font-size:8pt; font-family:Tahoma; font-weight:normal;
color:maroon; }
<link rel="stylesheet" href="css/demostyle.css">
<body bgcolor="white">

<p align="center" class="title">
<asp:label id="Message" runat="server" />

<% if(!Page.IsPostBack) { %>
<p align="center">All fields are required.</p>

<form id="Form1" method="post" runat="server">
<table width="80%" border="0" align="center" cellpadding="2" cellspacing="2">
<td width="20%" align="right">From : </td>
<td><input type="text" name="from"></td>
<td align="right">To : </td>
<td><input type="text" name="to"></td>
<td align="right">MailFormat : </td>
<select name="format">
<option value="text">Text</option>
<option value="html">HTML</option>
<td align="right">Subject : </td>
<td><input type="text" name="subject" style="width:400;"></td>
<td valign="top" align="right">Body : </td>
<textarea cols="5" rows="10" name="body" style="width:400;">
<td> </td>
<input id="Submit1" type="submit" OnServerClick="Send_Email" runat="server"
class="submit" value=" " /> Send Email!
<% } %>


Author: Karthikeyan Anbarasan       [Moderator]      
Posted Date: January 03, 2011     Points: 5   

Use the below code for sending mail.

MailMessage msgMail = new MailMessage();

msgMail.To = "christophw@sleeper.Dev.AlfaSierraPapa.Com";
msgMail.From = "webmaster@aspheute.com";
msgMail.Subject = "Attachment Test";

msgMail.BodyFormat = MailFormat.Text;
msgMail.Body = "Check out the attachment!";
msgMail.Attachments.Add(new MailAttachment("c:\\Document.pdf"));


Response.Write("Email was sent");

Mark as Answer if the answer solves your issue!!!
Author: Dhiraj Ranka             
Posted Date: January 04, 2011     Points: 5   

Try this code

NameValueCollection settings;
Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");

AppSettingsSection appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings");
settings = System.Configuration.ConfigurationManager.AppSettings;

string UN = settings["UserName"];
string PASS = settings["Password"];
string SMTP = settings["MailServer"];
int PORT = Convert.ToInt32(settings["MailServerPort"]);
foreach (string str in sendto)
body = "Your body text goes here";
MailMessage msg = new MailMessage();
msg.From = new MailAddress(UN);
msg.To.Add(new MailAddress(str));
msg.Subject = "NX27K Alert - " + DateTime.Now.ToShortDateString();
msg.Body = body;
msg.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = SMTP;
smtp.Port = PORT;
smtp.Credentials = new System.Net.NetworkCredential(UN, PASS);
smtp.EnableSsl = true;

Hope this helps.

Thanks & Regards,
Dhiraj Ranka
http://www.twitter.com/dhirajranka | http://www.dhirajranka.com

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend