473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

CDO. Message Problems

4
Is Exchange/Outlook required to be on the same box as web server to function properly.
If not, are there any dangers in using CDO in directing a web form contents to an email address (mine of course)?
I'm not an expert programmer, but am somewhat familiar with .asp and .net. I'll let you know if you go over my head. Any help would be greatly appreciated.
Jul 28 '06 #1
8 11831
sashi
1,754 Expert 1GB
hi there,

not really.. all you need is a an smtp server to manage outgoing mail messages.. it doesn't have to be on the same box.. dangers? well.. not that i know of as long as you are behind a properly configured firewall or an antivirus.. take care.
Jul 29 '06 #2
dduran
4
Thanks Sashi for the quick reply. I can't seem to get the code right to use a remote smtp server. Any suggestions? I have tried the following code with no success...what do you think?

Start David's Test Code----
Expand|Select|Wrap|Line Numbers
  1.  <% 
  2. option explicit
  3.  
  4. '---------------------------------------------------------------------------------------------------
  5. 'FORM MAIL SCRIPT
  6. '----------------
  7. 'usage:
  8. '<form ACTION="sendmail.asp" ...>
  9. '
  10. 'hidden fields:
  11. '    redirect    - the url to redirect to when the mail has been sent (REQUIRED)
  12. '    mailto        - the email address of the recipient (separate multiple recipients with commas) (REQUIRED)
  13. '    cc            - the email address of the cc recipient (separate multiple recipients with commas) (OPTIONAL)
  14. '    bcc            - the email address of the bcc recipient (separate multiple recipients with commas) (OPTIONAL)
  15. '    mailfrom    - the email address of the sender (REQUIRED)
  16. '    subject        - the subject line of the email (REQUIRED)
  17. '    message        - the message to include in the email above the field values. not used when a template is being used. (OPTIONAL)
  18. '    template    - specifies a text or html file to use as the email template, relative to the location of the sendmail script. (e.g. ../email.txt)
  19. '                 A template should reference form fields like this: [$Field Name$]
  20. '    html        - if this has the value "yes", the email will be sent as an html email. only used if a template is supplied.
  21. '    testmode    - if this is set to "yes", the email contents will be written to the screen instead of being emailed.
  22. '---------------------------------------------------------------------------------------------------
  23. dim pde : set pde = createobject("scripting.dictionary")
  24. '---------------------------------------------------------------------------------------------------
  25. 'PREDEFINED ADDRESSES for the "mailto" hidden field
  26. 'if you don't want to reveal email addresses in hidden fields, use a token word instead and specify
  27. 'below which email address it applies to. e.g. <input type="hidden" name="mailto" value="%stratdepartment%">
  28. 'ALSO, in the same way, you can use %mailfrom% to hide the originating email address
  29. pde.add "%DirectMailRequest%", "thermocraft@satx.rr.com"
  30. 'pde.add "%salesenquiry%", "anotheremail@someaddress.com"
  31. '---------------------------------------------------------------------------------------------------
  32.  
  33. function getTextFromFile(path)
  34.     dim fso, f, txt
  35.     set fso = createobject("Scripting.FileSystemObject")
  36.     if not fso.fileexists(path) then
  37.         getTextFromFile = ""
  38.         exit function
  39.     end if
  40.     set f = fso.opentextfile(path,1)
  41.     if f.atendofstream then txt = "" else txt = f.readall
  42.     f.close
  43.     set f = nothing
  44.     set fso = nothing
  45.     getTextFromFile = txt
  46. end function
  47.  
  48. dim redir, mailto, mailfrom, subject, item, body, cc, bcc, message, html, template, usetemplate, testmode
  49. redir = request.form("redirect")
  50. mailto = request.form("mailto")
  51. if pde.exists(mailto) then mailto = pde(mailto)
  52. cc = request.form("cc")
  53. bcc = request.form("bcc")
  54. mailfrom = request.form("mailfrom")
  55. if mailfrom = "" then mailfrom = pde("%mailfrom%")
  56. subject = request.form("subject")
  57. message = request.form("message")
  58. template = request.form("template")
  59. 'testmode = lcase(request.form("testmode"))="no"
  60.  
  61. if len(template) > 0 then template = getTextFromFile(server.mappath(template))
  62. if len(template) > 0 then usetemplate = true else usetemplate = false
  63. dim msg : set msg = server.createobject("CDO.Message")
  64. msg.subject = subject
  65. msg.to = mailto
  66. msg.from = mailfrom
  67. if len(cc) > 0 then msg.cc = cc
  68. if len(bcc) > 0 then msg.bcc = bcc
  69.  
  70. if not usetemplate then
  71.     body = body & message & vbcrlf & vbcrlf
  72. else
  73.     body = template
  74. end if
  75. for each item in request.form
  76.     select case item
  77.         case "redirect", "mailto", "cc", "bcc", "subject", "message", "template", "html", "testmode"
  78.         case else
  79.             if not usetemplate then
  80.                 if item <> "mailfrom" then body = body & item & ": " & request.form(item) & vbcrlf & vbcrlf
  81.             else
  82.                 body = replace(body, "[$" & item & "$]", replace(request.form(item),vbcrlf,"<br>"))
  83.             end if
  84.     end select
  85. next
  86.  
  87. if usetemplate then 'remove any leftover placeholders
  88.     dim rx : set rx = new regexp
  89.     rx.pattern = "\[\$.*\$\]"
  90.     rx.global = true
  91.     body = rx.replace(body, "")
  92. end if
  93.  
  94. if usetemplate and lcase(request.form("html")) = "yes" then
  95.     msg.htmlbody = body
  96. else
  97.     msg.textbody = body
  98. end if
  99. if testmode then
  100.     if lcase(request.form("html")) = "yes" then
  101.         response.write "<pre>" & vbcrlf
  102.         response.write "Mail to: " & mailto & vbcrlf
  103.         response.write "Mail from: " & mailfrom & vbcrlf
  104.         if len(cc) > 0 then response.write "Cc: " & cc & vbcrlf
  105.         if len(bcc) > 0 then response.write "Bcc: " & bcc & vbcrlf
  106.         response.write "Subject: " & subject & vbcrlf & string(80,"-") & "</pre>"
  107.         response.write body
  108.     else
  109.         response.write "<html><head><title>Sendmail.asp Test Mode</title></head><body><pre>" & vbcrlf
  110.         response.write "Mail to: " & mailto & vbcrlf
  111.         response.write "Mail from: " & mailfrom & vbcrlf
  112.         if len(cc) > 0 then response.write "Cc: " & cc & vbcrlf
  113.         if len(bcc) > 0 then response.write "Bcc: " & bcc & vbcrlf
  114.         response.write "Subject: " & subject & vbcrlf & vbcrlf
  115.         response.write string(80,"-") & vbcrlf & vbcrlf & "<span style=""color:blue;"">"
  116.         response.write body & "</span>" & vbcrlf & vbcrlf
  117.         response.write string(80,"-") & vbcrlf & "**END OF EMAIL**</pre></body></html>"
  118.     end if
  119. else
  120.     msg.send
  121.     response.redirect redir
  122. end if
  123. set msg = nothing
  124. %>
  125.  
End David's Test Code---
Jul 31 '06 #3
hi there,
you need to use the configuaration object for ur settings of smtp server and the port.

something like ths

Expand|Select|Wrap|Line Numbers
  1.  
  2. Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration") 
  3.         objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "127.0.0.1" 
  4.         objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
  5. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
  6. objCDOSYSCon.Fields.Update
Aug 2 '06 #4
dduran
4
Does smtpserver have to be an ip address? Can I use "smtp-server.satx.rr.com"?
Also, does it matter where I Set the objCDOSYSCon?
The code I'm using is accepting the info from my form, then redirecting to a thank you page. But it is still not sending the information to my email address.

I place the objCDOSYSCon near ("CDO.message").

Expand|Select|Wrap|Line Numbers
  1.  <% 
  2. option explicit
  3.  
  4. 'Dim objCDOSYSCon
  5. 'Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration") 
  6. 'objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp-server.satx.rr.com" 
  7. 'objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
  8. 'objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
  9. 'objCDOSYSCon.Fields.Update
  10.  
  11. '---------------------------------------------------------------------------------------------------
  12. 'FORM MAIL SCRIPT
  13. '----------------
  14. 'usage:
  15. '<form ACTION="sendmail.asp" ...>
  16. '
  17. 'hidden fields:
  18. '    redirect    - the url to redirect to when the mail has been sent (REQUIRED)
  19. '    mailto        - the email address of the recipient (separate multiple recipients with commas) (REQUIRED)
  20. '    cc            - the email address of the cc recipient (separate multiple recipients with commas) (OPTIONAL)
  21. '    bcc            - the email address of the bcc recipient (separate multiple recipients with commas) (OPTIONAL)
  22. '    mailfrom    - the email address of the sender (REQUIRED)
  23. '    subject        - the subject line of the email (REQUIRED)
  24. '    message        - the message to include in the email above the field values. not used when a template is being used. (OPTIONAL)
  25. '    template    - specifies a text or html file to use as the email template, relative to the location of the sendmail script. (e.g. ../email.txt)
  26. '                 A template should reference form fields like this: [$Field Name$]
  27. '    html        - if this has the value "yes", the email will be sent as an html email. only used if a template is supplied.
  28. '    testmode    - if this is set to "yes", the email contents will be written to the screen instead of being emailed.
  29. '---------------------------------------------------------------------------------------------------
  30. dim pde : set pde = createobject("scripting.dictionary")
  31. '---------------------------------------------------------------------------------------------------
  32. 'PREDEFINED ADDRESSES for the "mailto" hidden field
  33. 'if you don't want to reveal email addresses in hidden fields, use a token word instead and specify
  34. 'below which email address it applies to. e.g. <input type="hidden" name="mailto" value="%stratdepartment%">
  35. 'ALSO, in the same way, you can use %mailfrom% to hide the originating email address
  36. pde.add "%contactform%", "davidd@thermo-craft.com"
  37. pde.add "%salesenquiry%", "dave.dura@gmail.com"
  38. '---------------------------------------------------------------------------------------------------
  39.  
  40. function getTextFromFile(path)
  41.     dim fso, f, txt
  42.     set fso = createobject("Scripting.FileSystemObject")
  43.     if not fso.fileexists(path) then
  44.         getTextFromFile = ""
  45.         exit function
  46.     end if
  47.     set f = fso.opentextfile(path,1)
  48.     if f.atendofstream then txt = "" else txt = f.readall
  49.     f.close
  50.     set f = nothing
  51.     set fso = nothing
  52.     getTextFromFile = txt
  53. end function
  54.  
  55. dim redir, mailto, mailfrom, subject, item, body, cc, bcc, message, html, template, usetemplate, testmode
  56. redir = request.form("redirect")
  57. mailto = request.form("mailto")
  58. if pde.exists(mailto) then mailto = pde(mailto)
  59. cc = request.form("cc")
  60. bcc = request.form("bcc")
  61. mailfrom = request.form("mailfrom")
  62. if mailfrom = "" then mailfrom = pde("%mailfrom%")
  63. subject = request.form("subject")
  64. message = request.form("message")
  65. template = request.form("template")
  66. testmode = lcase(request.form("testmode"))="no"
  67.  
  68. if len(template) > 0 then template = getTextFromFile(server.mappath(template))
  69. if len(template) > 0 then usetemplate = true else usetemplate = false
  70. Dim objCDOSYSCon
  71.     set objCDOSYSCon = Server.CreateObject ("CDO.Configuration") 
  72.     objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp-server.satx.rr.com" 
  73.     objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
  74.     objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
  75.     objCDOSYSCon.Fields.Update
  76. dim msg : set msg = server.createobject("CDO.Message")
  77. msg.subject = subject
  78. msg.to = mailto
  79. msg.from = mailfrom
  80. if len(cc) > 0 then msg.cc = cc
  81. if len(bcc) > 0 then msg.bcc = bcc
  82.  
  83. if not usetemplate then
  84.     body = body & message & vbcrlf & vbcrlf
  85. else
  86.     body = template
  87. end if
  88. for each item in request.form
  89.     select case item
  90.         case "redirect", "mailto", "cc", "bcc", "subject", "message", "template", "html", "testmode"
  91.         case else
  92.             if not usetemplate then
  93.                 if item <> "mailfrom" then body = body & item & ": " & request.form(item) & vbcrlf & vbcrlf
  94.             else
  95.                 body = replace(body, "[$" & item & "$]", replace(request.form(item),vbcrlf,"<br>"))
  96.             end if
  97.     end select
  98. next
  99.  
  100. if usetemplate then 'remove any leftover placeholders
  101.     dim rx : set rx = new regexp
  102.     rx.pattern = "\[\$.*\$\]"
  103.     rx.global = true
  104.     body = rx.replace(body, "")
  105. end if
  106.  
  107. if usetemplate and lcase(request.form("html")) = "yes" then
  108.     msg.htmlbody = body
  109. else
  110.     msg.textbody = body
  111. end if
  112. if testmode then
  113.     if lcase(request.form("html")) = "yes" then
  114.         response.write "<pre>" & vbcrlf
  115.         response.write "Mail to: " & mailto & vbcrlf
  116.         response.write "Mail from: " & mailfrom & vbcrlf
  117.         if len(cc) > 0 then response.write "Cc: " & cc & vbcrlf
  118.         if len(bcc) > 0 then response.write "Bcc: " & bcc & vbcrlf
  119.         response.write "Subject: " & subject & vbcrlf & string(80,"-") & "</pre>"
  120.         response.write body
  121.     else
  122.         response.write "<html><head><title>Sendmail.asp Test Mode</title></head><body><pre>" & vbcrlf
  123.         response.write "Mail to: " & mailto & vbcrlf
  124.         response.write "Mail from: " & mailfrom & vbcrlf
  125.         if len(cc) > 0 then response.write "Cc: " & cc & vbcrlf
  126.         if len(bcc) > 0 then response.write "Bcc: " & bcc & vbcrlf
  127.         response.write "Subject: " & subject & vbcrlf & vbcrlf
  128.         response.write string(80,"-") & vbcrlf & vbcrlf & "<span style=""color:blue;"">"
  129.         response.write body & "</span>" & vbcrlf & vbcrlf
  130.         response.write string(80,"-") & vbcrlf & "**END OF EMAIL**</pre></body></html>"
  131.     end if
  132. else
  133.     msg.send
  134.     response.redirect redir
  135. end if
  136. set msg = nothing
  137. %>
  138.  
Aug 10 '06 #5
sashi
1,754 Expert 1GB
Hi Duran,

the practical way is to leave the ip of your SMTP server to it's localhost address, which is 127.0.0.1.. this is if you have your SMTP server.. you can also specify an external ip address or hostname if you have no SMTP in server your network.. take care my fren..
Aug 11 '06 #6
dduran
4
Sashi and tejaswini

I got everything to work!!! Thanks for your help. This is the first time I use a forum to ask for help, I'm glad I did. Mission Accomplished!!!

David Duran
Aug 16 '06 #7
sashi
1,754 Expert 1GB
Hi Dave,

at last ah? :) good luck and take care my fren.. :)
Aug 17 '06 #8
Niheel
2,460 Expert Mod 2GB
Reminder to members posting to this thread: Please use code tags when posting code.
Aug 22 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: John | last post by:
Could anyone please help me on this?? I have a php script page, which is basically quiz. Visitors (after login in with their email address) are supposed to answer each question, and when they...
5
by: Paul Cheevers | last post by:
Hi, This is driving me nuts to say the least!!!!! I am trying to send an email from some server side ASP code and the CC field is giving me some problems. The code works fine if I have one...
4
by: Bhavna | last post by:
Hello Does anyone know what this message could be regarding? The application seems to fall over on the following line. Dim variable1 As SqlString = Arraylist1(i The first time the code runs...
5
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
6
by: rbazinet | last post by:
I have a VS 2003 C# project, web app with a bunch of DLL's. When I compile my project I often times get this message: Unexpected error creating debug information file 'C:\DevProjects\Allstar...
4
by: Liz Patton | last post by:
Here's the exception: System.Exception: Unable to send mail: Could not access 'CDO.Message' object. ---> System.Web.HttpException: Could not access 'CDO.Message' object. --->...
16
by: Neil Stevens | last post by:
Hi, I would like to implements a message queue much like i used to in vb6 as below:- dim myMsg as MSG while (PeekMessage(myMsg, hWnd, 0, 0)) if myMsg.Msg = WM_QUIT Then End end if
1
by: shots86 | last post by:
I am having problems sending emails via the CDO.Message object from an ASP script which was working fine. On the server I can still send emails via the CDO.Message from a .vbs script executed on...
71
by: desktop | last post by:
I have read in Bjarne Stroustrup that using malloc and free should be avoided in C++ because they deal with uninitialized memory and one should instead use new and delete. But why is that a...
1
by: Ben | last post by:
Environment Info: - MS Access Sales System (front-end) - SQL Server Standard (back-end) Information of the Problem: ** In the Inventory items data: - when user enters a new item and does...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.