All source code in .Net Ask a .Net Pro Discussion Forum Categories All jobs in .Net
Quick Search for:  in language:    
Sending,email,ASPNET,breeze,Check,example,Not
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
Categories Search Newest Code Coding Contest Code of the Day Ask A Pro Jobs Upload
.Net Stats

 Code: 479,617. lines
 Jobs: 497. postings

 How to support the site

 
Sponsored by:

 
You are in::
 

Microsoft® Visual Studio 2005

Welcome New User
Logout






Latest postings for .Net.
Compare two images, very fast (unmanaged & managed)
By Ole Rasmussen on 5/22


Click here to see a screenshot of this code!RichTextBox Semi/Fully Transparent .., OwnerDraw Menu
By Dennis M. Santiago on 5/22

(Screen Shot)

Click here to see a screenshot of this code!Finite State Machine Editor
By lafsam@hotmail. com on 5/4

(Screen Shot)

Click here to see a screenshot of this code!Project Carbon (C# Packet Spy)
By Brandon Scott on 5/19

(Screen Shot)

Exporting ADO.NET DataSet To Excel
By Igor Krupitsky on 5/18


Click here to see a screenshot of this code!Filtering Inputs In a Textbox
By Patrick Guimalan on 5/18

(Screen Shot)

Click here to see a screenshot of this code!BER/CER/DER Decoder
By OGUZ_OZGUL on 5/17

(Screen Shot)

Click here to see a screenshot of this code!Prime number generator / generador de números primos
By Luis Salgado on 5/17

(Screen Shot)

Click here to see a screenshot of this code!MinesXP Shareware OpenGL game
By Saadat Ali Shah on 5/16

(Screen Shot)

XSLT in ASP.NET example
By Igor Krupitsky on 5/16


Click here to see a screenshot of this code!Controlling Multiples of the Same Form
By 0r3n on 5/16

(Screen Shot)

Tic Tac Toe
By Vitor Casquinha da Costa on 5/15


Click here to see a screenshot of this code!Terminal Services Status Page
By Igor Krupitsky on 5/15

(Screen Shot)

Click here to see a screenshot of this code!Weather Buddy
By Don Steele on 5/11

(Screen Shot)

RunDosCommand Function
By Igor Krupitsky on 5/2


Windows Service Installation Script
By Igor Krupitsky on 5/10


ImageGenByJavaI nASPNET
By Amit Kumar Gaur on 5/9


Click here to see a screenshot of this code!Amortization schedule
By Robert Arnold on 5/3

(Screen Shot)

online purchase
By mohib-ullah on 1/30


Click here to see a screenshot of this code!mIRC Control
By guideX on 5/8

(Screen Shot)

ExcelGen
By Jason Davis on 5/8


LoginDialog
By Jason Davis on 5/8


Click here to see a screenshot of this code!DIV Table
By Igor Krupitsky on 5/7

(Screen Shot)

Click here to see a screenshot of this code!Image Factory v1.0
By AliAmjad on 5/7

(Screen Shot)

Click here to see a screenshot of this code!Parameter Discovery on Ms Access With XML option. Using Microsoft Patterns and Practices Ver 3
By PatrickQuinn on 1/3

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Help us improve the site!
Take the Planet Source Code survey today!


Affiliate Sites




Other Programming Sites
 Code Project
 Developers Dex
 Developer Fusion
 Programmer's Heaven
 Tek-Tips Forums

 DevGuru
 Scripts
 VisualBuilder.com
 Web Design
ASPAlliance
 What is XML?
 XML Pitstop
 Your HTML Source
 ZVON.ORG
 
 
   

How to send an email in ASP.net

Print
Email
 
VB icon
Submitted on: 3/21/2002 2:14:12 PM
By: Ian Ippolito (RAC)
 
Level: Beginner
User Rating: By 9 Users
Compatibility:VB.NET, ASP.NET

Users have accessed this code 11062 times.
 
author picture
(About the author)
 
     Sending email in ASP.NET is a breeze! Check out this example. Note that docs say that the .SMTPServer property is optional...if you don't specify one, Windows queues up your email for you. However, I haven't tested out this method of sending mail.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    //**************************************
    //     
    // Name: How to send an email in ASP.net
    //     
    // Description:Sending email in ASP.NET 
    //     is a breeze! Check out this example. Not
    //     e that docs say that the .SMTPServer pro
    //     perty is optional...if you don't specify
    //     one, Windows queues up your email for yo
    //     u. However, I haven't tested out this me
    //     thod of sending mail.
    // By: Ian Ippolito (RAC)
    //
    //This code is copyrighted and has
    // limited warranties.Please see http://
    //     www.Planet-Source-Code.com/vb/scripts/Sh
    //     owCode.asp?txtCodeId=161&lngWId=10
    //for details.
    //**************************************
    //     
    
    Dim mmMail As New System.Web.Mail.MailMessage()
    Dim objSmtpServer As System.Web.Mail.SmtpMail
    mmMail.From = "me@me.com"
    mmMail.To = "you@you.com"
    mmMail.Subject = "My subject"
    mmMail.Body = "My body"
    objSmtpServer.SmtpServer = "my smtp server"
    objSmtpServer.Send(mmMail)


Other 10 submission(s) by this author

 

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
5/8/2002 1:18:58 PMSam Moses

Thank you for this simple example. It straight forward and seems to work on my dev server. Do you know if there is a way to configure a different port with this type of code? My server sends e-mail on port 8025. Thanks -Sam
(If this comment was disrespectful, please report it.)

 
5/8/2002 1:40:15 PMIan Ippolito (psc)

Sam,

Not really...I assume you tried adding the port to the server name and that didn't work? If so, the documentation is not the best on how (or if) this can be done.

Ian
(If this comment was disrespectful, please report it.)

 
5/22/2002 3:54:07 PMBrian

I was wondering why it does not work for me. I get the following error.

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/PROTEUS/amazing/CUST_sendemail_submit.asp, line 2, column 11
Dim mmMail As New System.Web.Mail.MailMessage()
----------^


I have installled asp.net on my computer, but am not completely sure if there is something else that is not configured. Obviously there is.
(If this comment was disrespectful, please report it.)

 
5/26/2002 6:37:39 AMVarun

i really need a code to send an email from within vb. your code looks good but it doesnt work. i get the same error msg as the previous one had mentioned. i need a code that will work 100% on all comps.
(If this comment was disrespectful, please report it.)

 
8/8/2002 5:01:46 PMEJ T

I dont get an error but my firewall says my appconect to there internet and that it was acting like a smtp server but it didnt send.
(If this comment was disrespectful, please report it.)

 
10/22/2002 8:57:53 PMGreyMatter

Brian -- you need to rename the file to .aspx
(If this comment was disrespectful, please report it.)

 
10/22/2002 9:00:39 PMIan Ippolito (psc)

Nice catch, GreyMatter! ;)

Ian
(If this comment was disrespectful, please report it.)

 
11/1/2002 8:43:03 AM

Hm, I've got trouble with it, too.
But my error-message tells: "The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for MyAccount@MyHost.com"
(If this comment was disrespectful, please report it.)

 
11/1/2002 4:45:01 PMIan Ippolito (psc)

Your SMTP server is telling you that it isn't configured to relay properly. That is beyond the scope of this article, so if you don't know how to configure it, consult with a local systems engineer.

Ian
(If this comment was disrespectful, please report it.)

 
12/25/2002 4:28:28 AM

If anyone need help on this, I can tell you what to do, very easy! Just e-mail!
(If this comment was disrespectful, please report it.)

 
1/9/2003 6:09:35 PM

Hm, I've got trouble with it, too.
my error-message tells:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: The value of "SendUsing" configuration is incorrect.

So i dont know what its means ?

Someone could you help me ?

Thx

Elv
(If this comment was disrespectful, please report it.)

 
4/30/2003 9:16:11 AMArne Garvander

Howcome there is no authentication to mail server? Ae you using a relay server or a spam server?
(If this comment was disrespectful, please report it.)

 
4/30/2003 10:40:10 AMIan Ippolito (RAC)

A relay server. Relays can be secured in a # of ways, including IP etc. that don't require authentication. That is beyond the scope of this article however.

Ian
(If this comment was disrespectful, please report it.)

 
12/26/2003 6:40:05 AM

Hi Ian, Your code is great and work a treat. I created a form with a submit button to call your code. It works great except when I refresh the page, it automatically send another mail message out which I don't want. Any way to get around that? Thanks in advance.
(If this comment was disrespectful, please report it.)

 
12/29/2003 12:18:26 PMIan Ippolito (RAC)

A solution to that problem is to split the emailing page out from the 'confirmation' page. So after the code above do a response.redirect to another page where you show the confirmation page. Then if the user hits refresh it won't resend the email.
Ian

Ian
(If this comment was disrespectful, please report it.)

 
6/14/2004 10:33:19 PMJohnson Hernandez

Nice work dude, this is the one i am looking for the whole day.
(If this comment was disrespectful, please report it.)

 
2/7/2005 2:52:08 AMArvin Meralpis

Very useful yet simple.
Thanx for this code. 5 globes from me.
(If this comment was disrespectful, please report it.)

 
3/31/2006 6:31:48 AMTimothy Coutlakis

yeah, great for those who don't have access to MSDN

it would have been much more help to expand on how the smtp server works
(If this comment was disrespectful, please report it.)

 
5/6/2006 8:13:17 AMGreg

to install / configure iis virtual smtp server try here http://msdn2.microsoft.com/en-US/library/8b83ac7t.aspx
(If this comment was disrespectful, please report it.)

 
5/15/2006 5:56:25 AMsarvesh

nice
(If this comment was disrespectful, please