how to send an email in asp.net

Posted by Ud123 under ASP.NET on 11/29/2010 | Points: 10 | Views : 1943 | Status : [Member] | Replies : 4
hi,
i am new to asp.net,
i just want to send an email for my project,
can anyone help me?




Responses

Posted by: Laghaterohan on: 11/29/2010 [Member] Starter | Points: 25

Up
0
Down
Hi,

Here is a code snippet...modify as per your requirement.
Use namespace System.Net.Mail

SmtpClient smtpClient;
private void Connection()
{
smtpClient = new SmtpClient();
smtpClient.Host = ''
smtpClient.Port = ''
}

public MethodName ()
{
Connection();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress(' ');
message.From = fromAddress;
message.To.Add(ToAddress);
message.Subject = " ";
message.IsBodyHtml = false;
message.Body = ' '
smtpClient.Send(message);
}


Best Regards,
Rohan Laghate

Ud123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 11/29/2010 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
i have written an Article on this , look at this Article
http://www.dotnetfunda.com/articles/article747-how-to-send-an-email-using-gmail-in-aspnet-.aspx

Thank you for posting at Dotnetfunda
[Administrator]

Ud123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 11/29/2010 [Member] [MVP] Silver | Points: 25
Posted by: Lalji_mer on: 11/30/2010 [Member] Bronze | Points: 25

Up
0
Down
Try to below code sample
<%@ Import Namespace="System.Web" %>

<%@ Import Namespace="ASPEMAILLib" %>
<%@ Import Namespace="System.Reflection" %>


<script runat="server" LANGUAGE="C#">

void Page_Load(Object Source, EventArgs E)
{
// Change this to your own SMTP server
String strHost = "localhost";

if( IsPostBack )
{
// MailSender object declaration
ASPEMAILLib.IMailSender objMail;
objMail = new ASPEMAILLib.MailSender();

objMail.Host = strHost;

objMail.From = "info@persits.com"; // From address
objMail.FromName = "AspEmail Live Demo"; // optional

String strToAddress = txtTo.Value.Trim();

if( !Regex.IsMatch( strToAddress, @"(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})" ) )
{
txtMsg.InnerHtml = "<font color=red>Invalid email address.</font>";
return;
}

// To address, 2nd argument omitted.
objMail.AddAddress( txtTo.Value, Missing.Value );

// Message subject
objMail.Subject = objMail.EncodeHeader( txtSubject.Value, "UTF-8" );

// Enable Unicode
objMail.ContentTransferEncoding = "Quoted-Printable";
objMail.CharSet = "UTF-8";

// Message body
objMail.Body = txtBody.Value;

// Include a disclaimer
objMail.Body += "\r\n\r\n-----------------------------------\r\n\r\nThis message was generated by the AspEmail live demo on-line application. Persits Software, Inc. is not responsible for its content.";

try
{
objMail.Send(Missing.Value);
txtMsg.InnerHtml = "<font color=green>Success! Message sent to " + txtTo.Value + ".</font>";
}
catch(Exception e)
{
txtMsg.InnerHtml = "<font color=red>Error occurred: " + e.Message + "</font>";
}
}
}

</script>

<HTML>
<HEAD>

<META HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8">

<TITLE>AspEmail Live Demo: Unicode-enabled Message Sending</TITLE>
</HEAD>
<BODY style="font-family: arial narrow; font-size: 10pt">

<h2>AspEmail Live Demo: Unicode-enabled Message Sending</h2>

<P>


<FORM METHOD="POST" RUNAT="Server">

<TABLE CELLSPACING=2 CELLPADDING=2 BGCOLOR="#E0E0E0" style="border: 1pt black solid; border-collapse: collapse">
<TR>
<TD>To:</TD>
<TD><INPUT TYPE="TEXT" size="40" ID="txtTo" RUNAT="Server"></TD>
</TR>
<TR>
<TD>Subject:</TD>
<TD><INPUT TYPE="TEXT" size="40" ID="txtSubject" RUNAT="Server"></TD>
</TR>
<TR>
<TD valign="top">Body:</TD>
<TD><TEXTAREA ID="txtBody" RUNAT="Server" Rows="10" Cols="40"></TEXTAREA></TD>
</TR>
<TR>
<TD COLSPAN=2><INPUT TYPE="SUBMIT" NAME="Send" VALUE="Send Message" RUNAT="Server"></TD>
</TR>

</TABLE>

<P>

<div id="txtMsg" runat="server"/><BR>

</FORM>

</BODY>
</HTML>


Here more reference link will help you.
http://www.aspheute.com/english/20000918.asp
http://www.startvbdotnet.com/aspsite/extras/sendmail.aspx
http://www.dotnetcurry.com/ShowArticle.aspx?ID=65&AspxAutoDetectCookieSupport=1
http://www.aspnetemail.com/Examples.aspx

LP MER

Ud123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response