Solved

getting an email

Posted on 2008-06-19
7
200 Views
Last Modified: 2013-11-07
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!
0
Comment
Question by:mahmood_786
  • 3
  • 3
7 Comments
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 100 total points
ID: 21823436
it is quiet easy, you can do it with pure HTML by setting the target of a form to an email. Have a look to this example:
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_mail
0
 
LVL 1

Expert Comment

by:jacek_j1978
ID: 21823764
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
0
 

Author Comment

by:mahmood_786
ID: 21825728
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....??
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:mahmood_786
ID: 21825776
To Jaime!

The method you told me opens the outlook express!!! I want it happen without opening it!!!
0
 
LVL 1

Accepted Solution

by:
jacek_j1978 earned 400 total points
ID: 21829632
The solution I presented is using your smtp server, so it is sent from your account. I used this with MS Exchange Server account, but you can use it as well to configure it with hotmail, yahoo, gmail as well.
In code snippet you can find solution with gmail example.
You can see extra three properties: Credentials, EnableSsl and Port which you have to configure.
	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

		mailMessage.From = new MailAddress("username@gmail.com");

		// Set the recepient address of the mail message

		mailMessage.To.Add(new MailAddress("ToMailbox.jura@mailbox.com")); //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("smtp.gmail.com");

		smptClient.Credentials = new System.Net.NetworkCredential("username", "password");

		smptClient.EnableSsl = true;

		smptClient.Port = 587;

		// Send the mail message

		smptClient.Send(mailMessage);

	}

Open in new window

0
 

Author Comment

by:mahmood_786
ID: 21831240
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      
0
 
LVL 1

Expert Comment

by:jacek_j1978
ID: 21837690
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.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now