Send SMTP email from IIS (asp?)

Trying to change existing functionality of a webbased app.  Current app sends e-mail via client-side outlook called from VBScript.  Want to change to server-side sending of mail.

Current:  When send mail button is pressed, here's what happens:

A javascript (.js) file calls a vbscript file with the command: execScript("WriteTicketEmailTo()","VBScript");

Below is the current VBscript file.  Would like to replace the VBscript (or add to the Javascript) to utilize server-side SMTP sending.  Have downloaded several ActiveX controls.  The Javascript and VBScript samples all work fine when I run them stand-alone on the server.   When I add the code to the IIS pages, I get automation errors in my client.  I assume I need to be using ASP to get things to run server-side, not sure how to call.  What/how do I change the execScript command to call the following code vs. the current? - or how do I cut in javascript to get things to run server-side.

Thanks for any advice

<WANTED xxx.asp file>
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>

<P>

<%

Dim objSmtpMail
Set objSmtpMail = Server.CreateObject("AddEmail.SmtpMail")


Dim strResult, numResultCode
numResultCode = objSmtpMail.SimpleSendScriptable("w","x","y","z")
If numResultCode = 0 Then
    Response.Write "Sent successfully!"
Else
    Response.Write "Error " & numResultCode
    Response.Write "<BR>" & strResult
End If

%>

</P>

</BODY>
</HTML>


<CURRENT XXX.vbs file contents>1
Sub WriteTicketEmailTo()
      dim c, i
      Dim vTO, vCC, vBCC, vBody, vSubject
      Dim vForm

      on error resume next

      Set objOutlook = GetObject(,"Outlook.Application")

      If error.num <> 0 Then
            Set objOutlook = CreateObject("Outlook.Application")
            error.clear
      End If

      Set NS = objOutlook.GetNamespace("MAPI")
      NS.Logon

      Set objOutlookMsg = objOutlook.CreateItem(0)
      vTo = document.ticketemail.toLine.value
      vCC = document.ticketemail.toCCLine.value
      vBody = document.ticketemail.toBody.value
      vSubject = document.ticketemail.toSubject.value

      objOutlookMsg.To   = vTo
      objOutlookMsg.CC   = vCC
      objOutlookMsg.Body = vBody
      objOutlookMsg.Subject = vSubject

      objOutlookMsg.Save
      objOutlookMsg.Display(true)

      Set ObjOutlook = Nothing
      Set ObjOutlookMsg = Nothing
End Sub
hedrickbAsked:
Who is Participating?
 
MadhusudanbanikConnect With a Mentor Commented:
Below is the backend script to send a mail, when the details would be coming from a form on the main webpage. If you want to know how to call the asp then reply back.

<% if request.form("func1") = "Send Message" then

  email = trim(request.form("email"))

  subject = trim(request.form("subject"))

  message = trim(request.form("message"))



msg = "Web Form " & chr(10) & chr(10)

  msg = msg & "Name  : " & name & chr(10)

  msg = msg & "Email  : " & email & chr(10)

  msg = msg & "Message  : " & message & chr(10)



Set objMail = Server.CreateObject("CDO.Message")

  Set objConf = Server.CreateObject("CDO.Configuration")

  Set objFields = objConf.Fields

 
' SMTP Server Configuration

  With objFields

  .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1

  .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")  = "http://127.0.0.1"  'IP address of SMTP Server

  .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10

  .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25  ' port on which SMTP works

  .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"

  .Update

  End With

With objMail

  Set .Configuration = objConf

  .From = email

  .To = "xxx@xxx.com"    'Predefined

  .Subject = subject     'Predefined

  .TextBody = msg

  End With

  Err.Clear

  objMail.Send

response.write "<b>Thank you very much for your post.</b>"

end if
%>
0
 
hedrickbAuthor Commented:
Thanks for the reply - Guess that's what I was really asking - I need to know how to call the ASP.

0
 
rockymageeCommented:
Save this as testEmail.asp:

***************************************************************

<%
IF request("senMail") = 1 THEN
  SMTP.ServerAddr = "" 'email server
  SMTP.FromAddr = Request("emailadd") 'sender email address
  SMTP.AddRecipient "You", "you@you.com", 0 'add an email recipient
  SMTP.BodyFormat = 1 'html format
  SMTP.Subject = Request("subject") 'email subject
  SMTP.BodyText ="<html>NAME: " & Request("name") & "<br><br" & Request("desc") & "</html>" 'email body  

  ' USING CDONTS
  'Set objMailer = CreateObject("CDONTS.Newmail")
  'objMailer.From = Request("emailadd")
  'objMailer.To = "" 'YOUR EMAIL ADDRESS
  'objMailer.Subject = Request("subject")
  'objMailer.BodyFormat = 0
  'objMailer.Mailformat = 0
  'objMailer.Body = "NAME: " & Request("name") & "<br><br" & Request("desc")
  'objMailer.Send
END IF
%>

<form action="testEmail.asp" method="post">
<b>Send an e-mail:</b><br><br>                                                
Enter your name:<br>
<input type="text" size="40" name="name">
<br><br>
E-mail address:
<br>
<input type="text" size="40" name="emailadd">
<br><br>
Enter Subject:
<br>
<input type="text" size="40" name="subject">
<br><br>
Enter your message:
<br>
<textarea cols="70" rows="15" name="desc"></textarea>
<br><br>
<input type="submit" value="Send Message">
</form>                        


***************************************************************
0
 
rockymageeConnect With a Mentor Commented:
Couple small corrections:

***************************************************************

<%
IF request("sendMail") = "1" THEN
  SMTP.ServerAddr = "" 'email server
  SMTP.FromAddr = Request("emailadd") 'sender email address
  SMTP.AddRecipient "You", "you@you.com", 0 'add an email recipient
  SMTP.BodyFormat = 1 'html format
  SMTP.Subject = Request("subject") 'email subject
  SMTP.BodyText ="<html>NAME: " & Request("name") & "<br><br" & Request("desc") & "</html>" 'email body  

  ' USING CDONTS
  'Set objMailer = CreateObject("CDONTS.Newmail")
  'objMailer.From = Request("emailadd")
  'objMailer.To = "" 'YOUR EMAIL ADDRESS
  'objMailer.Subject = Request("subject")
  'objMailer.BodyFormat = 0
  'objMailer.Mailformat = 0
  'objMailer.Body = "NAME: " & Request("name") & "<br><br" & Request("desc")
  'objMailer.Send
END IF
%>

<form action="testEmail.asp" method="post">
<b>Send an e-mail:</b><br><br>                                                
Enter your name:<br>
<input type="text" size="40" name="name">
<br><br>
E-mail address:
<br>
<input type="text" size="40" name="emailadd">
<br><br>
Enter Subject:
<br>
<input type="text" size="40" name="subject">
<br><br>
Enter your message:
<br>
<textarea cols="70" rows="15" name="desc"></textarea>
<br><br>
<inpupt type="hidden" name="sendMail" value="1">
<input type="submit" value="Send Message">
</form>            

***************************************************************
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.