tags:

views:

64

answers:

3
+1  Q: 

Mailing in asp.net

Hi i have a problem in mailing in the C#.net. I want to mail to the email address but i do not want to open the Outlook. Is there any procedure to do this. Please help to mail in c#.net.

A: 

Sounds like your putting a mailto:... link on your form. This will always open the default mail client on the user's PC.

What you need to do is have a contact form and send the email via the server.

For more information see the following website:

System.Net.Mail
How do I send a plain text email? (System.Net.Mail)

For reference:

System.Net.Mail Namespace (MSDN)

Kev
Thanks for the kind plug (systemNetMail.com is my website). --Dave
dave wanta
@dave - it's an excellent resource. I send all my hosting customers there (and previously the System.Web.Mail way back when...).
Kev
+3  A: 

You will need access to an SMTP server. If you have that add the following to your web.config:

  <system.net>
    <mailSettings>
      <smtp>
        <network 
             host="relayServerHostname" 
             port="portNumber"
             userName="username"
             password="password" />
      </smtp>
    </mailSettings>
  </system.net>

And take a look at .NET's MailMessage class. here is an example of how to craete a basic MailMesage object:

   MailMessage message = new MailMessage(
      "[email protected]",
      "[email protected]",
      "Quarterly data report.",
      "See the attached spreadsheet.");

To send the message you will use the SmtpClient class (which is conviniently configured from your web.config if you added the xml i suggested above. Example:

   SmtpClient client = new SmtpClient();
   client.Send(message);
Abe Miessler
Whats the meaning of the relayhostname its a gmail,yahoomail or my hostname where i want to upload website. how can i find out the port number
Amit Thaper
This will be your SMTP server address. The port will typically be 25 but not always.
Abe Miessler
A: 

Hey,

The System.Net.Mail namespace was meant to do this; check this out: http://www.systemnetmail.com/

Brian
Thanks for the kind plug (systemNetMail.com is my website).
dave wanta
@Dave no problem, comes in handily when trying to help other users. Thanks for creating it.
Brian