Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2010, 01:27 AM
Authorized User
 
Join Date: Feb 2006
Posts: 63
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Hannibal
Default How to send E-mail from ASP

Hi,

How to send e-mail from ASP page?
In the mail content, I would like to keep a button.

How to achieve this?

Thank you.
 
Old March 9th, 2010, 04:36 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Please check the following link:
http://www.w3schools.com/asp/asp_send_email.asp

Code:
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="[email protected]"
myMail.To="[email protected]"
myMail.HTMLBody = "<h1>This is a message.</h1>"
myMail.Send
set myMail=nothing
__________________
Om Prakash Pant
Click the "Thanks" button if this post helped you.
 
Old March 9th, 2010, 04:43 AM
Authorized User
 
Join Date: Feb 2006
Posts: 63
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Hannibal
Default

I tried that code. It is not working in windows server 2003 machine.
 
Old March 9th, 2010, 05:31 AM
Authorized User
 
Join Date: Feb 2006
Posts: 63
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Hannibal
Default

Hi,

I tried the following code:
Code:
 
<%
   Option Explicit
  dim sName, sEmail, sMessage
 dim oCdoMail, oCdoConf, sConfURL
  if Request.Form("Action") <> "" then
    sName = Request.Form("Name")
    sEmail = Request.Form("Email")
    sMessage = Request.Form("Message")
  Set oCdoMail = Server.CreateObject("CDO.Message")
  Set oCdoConf = Server.CreateObject("CDO.Configuration")
  sConfURL = "http://schemas.microsoft.com/cdo/configuration/"
  with oCdoConf
   .Fields.Item(sConfURL & "sendusing") = 2
   .Fields.Item(sConfURL & "smtpserver") = "server name"
   .Fields.Item(sConfURL & "smtpserverport") = 25
   .Fields.Update
  end with
  with oCdoMail
   .From = "[email protected]"
   .To = sEmail
   .Subject = "My message subject"
   .TextBody = sMessage
   .HTMLBody = sMessage
   .Configuration = oCdoConf
   .Send
  end with
  Set oCdoConf = Nothing
  Set oCdoMail = Nothing
    response.write "Thanks for your message!"
  else
%>
<form method="post" action="<%=Request.ServerVariables("SCRIPT_NAME")%>">
<p>Name:<br /><input type="text" name="Name" /></p>
<p>E-mail:<br /><input type="text" name="Email" /></p>
<p>Message:<br /><textarea name="Message"></textarea></p>
<p><input type="submit" name="Action" value="Send" /></p>
</form>
<%
  end if
%>
But i am not getting the mail in my inbox. Could you help me in that.

Thank you
 
Old March 9th, 2010, 07:27 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

What is the error message you are getting?

Also check this URL for example & common error handling:
http://classicasp.aspfaq.com/email/h...-with-cdo.html
__________________
Om Prakash Pant
Click the "Thanks" button if this post helped you.
 
Old March 9th, 2010, 01:28 PM
Authorized User
 
Join Date: Jan 2010
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can try following C# code. It uses using System.Web.Mail namespace.


MailMessage mailmsg = new MailMessage();
mailmsg.Body = strMessage;
mailmsg.From = strFrom;
mailmsg.To = strTo;
mailmsg.Subject = strSubject;
SmtpMail.SmtpServer = strMailServer;
SmtpMail.Send(mailmsg);


Hope this helps,

Kushal
 
Old March 9th, 2010, 02:01 PM
Authorized User
 
Join Date: Jan 2010
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Default

System.Web.Mail is deprecated. You can use System.Net.Mail namespace instead.

The code is more or less same to what I posted before.

Kushal
 
Old March 9th, 2010, 08:10 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

You should be using CDOSYS. This code below will work providing you have the SMTP service up and running. All you need is to place your SMTP IP address against the StrSmartHost variable, place a .To and .From addresses. Do this and just run the page to send the mail


<%
Const cdoSendUsingPort = 2
Dim iMsg,iConf,Flds,strHTML,strSmartHost
StrSmartHost = "YourIPAddresshere"
set iMsg = CreateObject("CDO.Message")
set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
'set the CDOSYS configuration fields to use port 25 on the SMTP server
With Flds
.Item("http://schemas.microsoft.com/cdo/con...tion/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/con...ion/smtpserver") = strSmartHost
.Item("http://schemas.microsoft.com/cdo/con...nectiontimeout") = 10
.Update
End With
'apply the settings to the message
With iMsg
Set .Configuration = iConf
.To = "SomeValidAddress"
.From = "SomeValidAddress"
.Subject = "CDOSYS Test"
.HTMLBody = "Sent using CDOSYS..."
.Send
End With
' cleanup of variables
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
response.write "mail sent"
%>
__________________
Wind is your friend
Matt

Last edited by mat41; March 9th, 2010 at 08:13 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Send mail and attachments with PHP mail function Lofa Beginning PHP 1 June 2nd, 2008 03:24 PM
Send Mail with Attachment using Asp rajchennai J2EE 0 June 30th, 2007 01:39 AM
How to send the mail in ASP.NET n.nsivakumar ASP.NET 1.0 and 1.1 Professional 2 July 26th, 2006 03:49 PM
Send mail failed using asp.net anujrathi ASP.NET 1.0 and 1.1 Professional 1 June 22nd, 2006 07:59 PM
Send E-mail from .asp page LiDenning Classic ASP Professional 2 April 28th, 2006 05:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.