Link to home
Start Free TrialLog in
Avatar of mahmood_786
mahmood_786Flag for United Kingdom of Great Britain and Northern Ireland

asked on

getting an email

Hi,

I have a website.I want to build a page in the type of a feedback form where users  can write there comments and and it come to my email box.
Any body give me some solid ideas about this!
SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
All you have to do is to use System.Net.Mail namespace.
Default.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
 
public partial class _Default : System.Web.UI.Page 
{
        protected void btSend_Click(object sender, EventArgs e)
	{
		// Instantiate a new instance of MailMessage
		MailMessage mailMessage = new MailMessage();
		// Set the sender address of the mail message (it should be some of your mailboxes)
		mailMessage.From = new MailAddress("FromMailbox@mailbox.com");
		// Set the recepient address of the mail message
		mailMessage.To.Add(new MailAddress("ToMailbox.jura@mailbox.com"));
		mailMessage.Subject = "E-mail from: " + tbUserName.Text;
		// Set the body of the mail message
		mailMessage.Body = tbBody.Text;
		// Instantiate a new instance of SmtpClient
		SmtpClient smptClient = new SmtpClient("SmtpClientNameOrIP");
		// Send the mail message
		smptClient.Send(mailMessage);
	}
}
 
Defualt.aspx:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
		<asp:Label ID="Label2" runat="server" Text="Username:"></asp:Label>
		<br />
		<asp:TextBox ID="tbUserName" runat="server" Width="200px"></asp:TextBox>
		<br />
		<asp:Label ID="Label1" runat="server" Text="Message:"></asp:Label>&nbsp;<br />
		<asp:TextBox ID="tbBody" runat="server" Height="151px" Width="200px"></asp:TextBox>&nbsp;
		<br />
		<asp:Button ID="btSend" runat="server" OnClick="btSend_Click" Text="Send" /></div>
    </form>
</body>
</html>

Open in new window

defaultaspx.JPG
Avatar of mahmood_786

ASKER

To Jacek!

Thanks ...that seems promising. So using that sort of code which u described.I will get the email.I can add the sender's email field as well....so that I know where I am receiving it from....just wonder how the email is received to my inbox? although I they are not using their email client(the sender) e.g,hotmail,yahoo etc....??
To Jaime!

The method you told me opens the outlook express!!! I want it happen without opening it!!!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I get this error message by compiling the code you first sent!!!

Error      1      'ASP.default_aspx' does not contain a definition for 'btSend_Click'      C:\Documents and Settings\Micosoft User\My Documents\Visual Studio 2005\WebSites\WebSite6\Default.aspx      52      
This is only an example. In order to use it, you have to add a button. Then create Onclick command for your button, and copy the code from my btSend_Click method into the method that will be created. In examples code there are usually bindings to different methods. So you have to use examples in a smart way. I can't write all for you. But after some time of coding you will become familiar with all of these.