[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Send SMTP email from IIS (asp?)

Posted on 2007-10-09
6
Medium Priority
?
940 Views
Last Modified: 2008-09-17
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
0
Comment
Question by:hedrickb
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
Madhusudanbanik earned 1000 total points
ID: 20039742
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
 

Author Comment

by:hedrickb
ID: 20040233
Thanks for the reply - Guess that's what I was really asking - I need to know how to call the ASP.

0
 
LVL 6

Expert Comment

by:rockymagee
ID: 20041711
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
 
LVL 6

Assisted Solution

by:rockymagee
rockymagee earned 1000 total points
ID: 20041729
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month18 days, 1 hour left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question