|
|
| |
|
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 |
|
|
| |
| Your
Vote! |
|
See
Voting Log |
| |
| Other User Comments |
5/8/2002 1:18:58 PM: Sam
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 PM: Ian
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 PM: Brian
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 AM: Varun
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 PM: EJ
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 PM: GreyMatter
Brian
-- you need to rename the file to .aspx (If
this comment was disrespectful, please report
it.)
|
10/22/2002 9:00:39 PM: Ian
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 PM: Ian
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 AM: Arne
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 AM: Ian
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
PM: Ian
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 PM: Johnson
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 AM: Arvin
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 AM: Timothy
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 AM: Greg
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 AM: sarvesh
nice (If this comment was disrespectful, please |