Link to home
Start Free TrialLog in
Avatar of garethtnash
garethtnashFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Microsoft VBScript compilation error '800a0401' HELP CDOSYS ASP Problem

Hello Experts,

I'm having a small problem sending a web generated emails CDOSYS, I am trying to integrate them with ASP recordsets and send dynamically generated emails. However when I run the code below i get the following error -

"Microsoft VBScript compilation error '800a0401'

Expected end of statement

/emailtest/index2.asp, line 19

myMail.From="Recordset1.Fields.Item("JBSURLShort").Value, Recordset1.Fields.Item("JBSNoReplyEmail").Value"
"

I've dewtailed the code I have used below, I'm just teting at the moment, but would be grateful for your thoughts?

Many thanks

GTN
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../Connections/recruta2.asp" -->
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows
 
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_recruta2_STRING
Recordset1_cmd.CommandText = "SELECT JBSSiteID, JBSMetaTitle, JBSLogo, JBSMetaKeywords, JBSMetaDescription, JBSURLShort, JBSNoReplyEmail, JBSURL FROM dbo.JBSite WHERE JBSSiteID = 30" 
Recordset1_cmd.Prepared = true
 
Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="Recordset1.Fields.Item("JBSURLShort").Value, Recordset1.Fields.Item("JBSNoReplyEmail").Value"
myMail.ReplyTo="garethtnash@aol.com"
myMail.To="gareth.tannattnash@netsolva.co.uk"
myMail.TextBody="This is a test email"
myMail.Send
set myMail=nothing
Response.Redirect "../advertisefree.html"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
 
<body>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>

Open in new window

Avatar of Wayne Barron
Wayne Barron
Flag of United States of America image

you cannot do it the way you are doing it.

myMail.From="Recordset1.Fields.Item("JBSURLShort").Value, Recordset1.Fields.Item("JBSNoReplyEmail").Value"
myMail.ReplyTo="garethtnash@aol.com"


Needs to be

myMail.From="Recordset1.Fields.Item("JBSURLShort").Value"
myMail.ReplyTo="garethtnash@aol.com"

You cannot have 2 Email Address's in the FROM fields.
So instead, you use the
From
ReplyTo
The ReplyTo makes up fo the other From Address.

Good Luck
Carrzkiss
Avatar of garethtnash

ASKER

tried that mate, still getting this -
 
Microsoft VBScript compilation error '800a0401'
Expected end of statement
/emailtest/index2.asp, line 19 myMail.From="Recordset1.Fields.Item("JBSNoReplyEmail").Value"
What I was trying to do was -
myMail.From="name value, email address value"
 
Any thoughts mate please - thanks
Also.
If that is your real email address, you need to have the mod's to remove it.
As Spammers could grab a hold of it.

FromAddress = Recordset1.Fields.Item("JBSURLShort").Value

myMail.From="&FromAddress&"
myMail.ReplyTo="garethtnash@domain.com"

I think this is the better way of doing it.
Change the FromAddress Value to which ever one that you wish to use.

Carrzkiss
FromAddress = Recordset1.Fields.Item("JBSNoReplyEmail").Value

myMail.From="&FromAddress&"
myMail.ReplyTo="garethtnash@domain.com"


I am sorry, this is the only way that you will be able to do it I think.
You can try this (Untested)

FromName = Recordset1.Fields.Item("JBSURLShort").Value
FromAddress = Recordset1.Fields.Item("JBSNoReplyEmail").Value

myMail.From="&FromAddress&,&FromName&"
myMail.ReplyTo="garethtnash@domain.com"

I do not think that it is going to go through.
I will test it if you can give me a few moments.

Carrzkiss
Hi Mate,
 
I Must be completely missing some thing, I coded the page as below,
Checked my junk mail as nothing had come through, where I had an email from -
&FromAddress& (no email address)
 
Sorry mate, I must be being really dumb, (thanks for the heads up with the email -)

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../Connections/recruta2.asp" -->
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows
 
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_recruta2_STRING
Recordset1_cmd.CommandText = "SELECT JBSSiteID, JBSMetaTitle, JBSLogo, JBSMetaKeywords, JBSMetaDescription, JBSURLShort, JBSNoReplyEmail, JBSURL FROM dbo.JBSite WHERE JBSSiteID = 30" 
Recordset1_cmd.Prepared = true
 
Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<%
FromAddress = Recordset1.Fields.Item("JBSURLShort").Value
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="&FromAddress&"
myMail.ReplyTo="garethtnash@domain.com"
myMail.To="gareth@domain.com"
myMail.TextBody="This is a test email"
myMail.Send
set myMail=nothing
Response.Redirect "../advertisefree.html"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
 
<body>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>

Open in new window

Sorry, that is not going to work.
It will grab your Mail Server's Address and add it to the end of the name.
So.
You will need to have the name in the Submit of the Message or in the header of the body.
This should do what you need it for.
If not, let me know, and I will test it for you.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
FromAddress = (Recordset1("JBSURLShort"))
myMail.From="&FromAddress&"
myMail.ReplyTo="garethtnash@domain.com"
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Sorry.
Carrzkiss
Still seems to be coming in from &FromAddress&, am I doing something wrong?
 
It is going to be a dynamically created, addresses (to, from, reply to) with a dynamically created document, is this going to be possible?
 
Cheers my friend
I am going to ask a dumb question, so please bare for me on this OK?

myMail.ReplyTo="garethtnash@domain.com"
myMail.To="gareth@domain.com"

You are putting in your actual Email address here correct?
As I was using this as an Example in here, as you do not want to post your real address in the post here on EE.

So, confirm that you are indeed using your actual email address's, and if it does not work.
Then I will test it over here.

Also.
You stated. = Dynamic.
Dynamic meaning that you are send out multiple email to multiple people?

If you are going to be sending it out to everyone that is listed in the [JBSSiteID = 30]
(I remember your DB, and that is a lot of people)
Then this code is not going to work.

If you are going to generate the code to send out to a lot of people, then let me know.
And I can make up a demo to do just that.
(But cannot post it here, as it can be used illegallly, as a spammer script)

Let me know?
Carrzkiss
dynamic as in, the sender and receiver are both variable, as is the reply to, basically, its a job board system, there are 70 in total so the "myMail.From" depends upon which JB it is coming from, the "myMail.ReplyTo" is the email address of the actual applicant and the  "myMail.To" is the email address of the recruiter.
so in effect only one email is generated each time the script is run, just from different sites, to different recruiters, with different reply to addresses...
Of course the next thing is attaching the variable CV....
Any thoughts are really appreciated!!
ok.
In your Select Statement you have
>>WHERE JBSSiteID = 30"
That is the SiteID, so this is looking at the entire field for everyone that is listed for that #.
So if you have 1 - 1,000
It is going to look through all the columns for the # 30.

You need to look at the Indivisual's ID # within the database, and grab it out.
If you cannot get the ID, then I do not know if this is going to work.

You can send me over a sample of your database and I can see what I can do with it?

Carrzkiss
in this instance the email is being sent by the site noreply email , so there is only 1 email address in the database for where SiteID ='30'
 
So the emails are sent from noreply@ 'JB Site'
to the recruiters email address
and replied to the applicants email address
 
Hope I am making sense? the database and recordset are fine, they only produce 1 record, it is the CDOSYS script that I'm struggleing with..
 
Cheers  
Working

change line 23 to your Mailserver name.
="smtp.mailserver.net"

27, 28, 29 & 44
To your needs.

Let me know if you need any assistance with it.
Good Luck
Carrzkiss
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath ("Q_24413297.mdb") & ";"
objConn.Open
 
getS = Request.QueryString("ID")
Set objRs=Server.CreateObject("ADODB.RecordSet")
getSQL = "SELECT JBSSiteID, JBSMetaTitle, JBSLogo, JBSMetaKeywords, JBSMetaDescription, JBSURLShort, JBSNoReplyEmail, JBSURL FROM JBSite WHERE JBSSiteID="& getS &""
objRs.Open getSQL, objConn, 1, 1, 1
 
 
FromAddress = (objRs("JBSNoReplyEmail"))
 
 
Dim myMail
Set myMail = CreateObject("CDO.Message") 
     
'This section provides the configuration information for the remote SMTP server.
     
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="smtp.mailserver.net"
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
     
' If your server requires outgoing authentication uncomment the lines bleow and use a valid email address and password.
'myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
'myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="somemail@yourserver.com"
'myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="yourpassword"
     
myMail.Configuration.Fields.Update
     
'End remote SMTP server configuration section==
     
myMail.To = "webmaster@site1.com"
myMail.ReplyTo="webmaster@site.net"
myMail.Subject = "this is the subject"
myMail.From = FromAddress
     
' we are sending a text email.. simply switch the comments around to send an html email instead
'myMail.HTMLBody = "this is the body"
myMail.TextBody = "this is the body"
     
myMail.Send
     
Set myMail = Nothing 
Response.Redirect "../advertisefree.html"
Recordset1.Close()
Set Recordset1 = Nothing
 
%>

Open in new window

Oh.
forgot to add in.

send.asp?id=30

This will run the script.
(or) if you need all to be 30. Then you can change

getSQL = "SELECT JBSSiteID, JBSMetaTitle, JBSLogo, JBSMetaKeywords, JBSMetaDescription, JBSURLShort, JBSNoReplyEmail, JBSURL FROM JBSite WHERE JBSSiteID="& getS &""

to
getSQL = "SELECT JBSSiteID, JBSMetaTitle, JBSLogo, JBSMetaKeywords, JBSMetaDescription, JBSURLShort, JBSNoReplyEmail, JBSURL FROM JBSite WHERE JBSSiteID=30"

To suit your needs.
Good Luck
Carrzkiss
You are a star Carrzkiss,
I've just managed to find part of the solution too, see code below, I haven't routed it through my mail server yet, that will be stage 3 or 4...,  the problem I've got now is attaching a variable attachement, the rest is starting to work,.... thankfully.... any thoughts on the variable attachement???
 
 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../Connections/recruta2.asp" -->
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows
 
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_recruta2_STRING
Recordset1_cmd.CommandText = "SELECT JBSSiteID, JBSMetaTitle, JBSLogo, JBSMetaKeywords, JBSMetaDescription, JBSURLShort, JBSNoReplyEmail, JBSURL FROM dbo.JBSite WHERE JBSSiteID = 30" 
Recordset1_cmd.Prepared = true
 
Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<%
Dim jobapplication
Dim jobapplication_cmd
Dim jobapplication_numRows
 
Set jobapplication_cmd = Server.CreateObject ("ADODB.Command")
jobapplication_cmd.ActiveConnection = MM_recruta2_STRING
jobapplication_cmd.CommandText = "SELECT * FROM dbo.JBApplication WHERE JBAPID = '2931'" 
jobapplication_cmd.Prepared = true
 
Set jobapplication = jobapplication_cmd.Execute
jobapplication_numRows = 0
%>
<%
Dim ObjSendMail
Dim iConf
Dim Flds
     
Set ObjSendMail = Server.CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
     
Flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
     
'**** Path below may need to be changed if it is not correct
Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"
Flds.Update
     
Set ObjSendMail.Configuration = iConf
ObjSendMail.To = "gareth@domain.co.uk"
ObjSendMail.Subject = "this is the subject"
ObjSendMail.From = (Recordset1.Fields.Item("JBSNoReplyEmail").Value)
ObjSendMail.ReplyTo = (jobapplication.Fields.Item("JBAPEmail").Value)     
' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = "Please find the application of " & (jobapplication.Fields.Item("JBAPName").Value) & " for your vacancy advertised on " & (Recordset1.Fields.Item("JBSURLShort").Value) & "" & vbCRLF & "" & vbCRLF & (jobapplication.Fields.Item("JBAPCoveringLetter").Value)
ObjSendMail.Send
     
Set ObjSendMail = Nothing
Response.Redirect "../advertisefree.html"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
 
<body>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
<%
jobapplication.Close()
Set jobapplication = Nothing
%>

Open in new window

This should do it for you.
Let me know if you have any questions.
Please read the liner notes within' the code.

Carrzkiss
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../Connections/recruta2.asp" -->
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows
 
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_recruta2_STRING
Recordset1_cmd.CommandText = "SELECT JBSSiteID, JBSMetaTitle, JBSLogo, JBSMetaKeywords, JBSMetaDescription, JBSURLShort, JBSNoReplyEmail, JBSURL FROM dbo.JBSite WHERE JBSSiteID = 30" 
Recordset1_cmd.Prepared = true
 
Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<%
Dim jobapplication
Dim jobapplication_cmd
Dim jobapplication_numRows
 
Set jobapplication_cmd = Server.CreateObject ("ADODB.Command")
jobapplication_cmd.ActiveConnection = MM_recruta2_STRING
jobapplication_cmd.CommandText = "SELECT * FROM dbo.JBApplication WHERE JBAPID = '2931'" 
jobapplication_cmd.Prepared = true
 
Set jobapplication = jobapplication_cmd.Execute
jobapplication_numRows = 0
%>
<%
Dim ObjSendMail
Dim iConf
Dim Flds
     
Set ObjSendMail = Server.CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
     
Flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
     
'**** Path below may need to be changed if it is not correct
Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"
Flds.Update
' list all varialbes here, give them a "Name" to be used in your TextBody, ReplyTo, From and any other area
PName=(jobapplication("JBAPName"))
URLShort=(Recordset1("JBSURLShort"))
CovLetter=(jobapplication("JBAPCoveringLetter"))
ReplyMail=(Recordset1("JBSNoReplyEmail"))
PEmail=(jobapplication("JBAPEmail"))
' you do not really have to use:   (Recordset1.Fields.Item("JBSNoReplyEmail").Value).
' this can be cut down by doing this: (Recordset1("JBSNoReplyEmail"))
' They both do the same exact thing. This is usually a Generated Code that does it like that. Dreamweaver is one of them.
     
Set ObjSendMail.Configuration = iConf
ObjSendMail.To = "gareth@domain.co.uk"
ObjSendMail.Subject = "this is the subject"
ObjSendMail.From = ReplyMail
ObjSendMail.ReplyTo = PEmail     
' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = "Please find the application of " & PName & " for your vacancy advertised on " & URLShort & "" & vbCRLF & "" & vbCRLF & CovLetter
ObjSendMail.Send
     
Set ObjSendMail = Nothing
Response.Redirect "../advertisefree.html"
%>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
<%
jobapplication.Close()
Set jobapplication = Nothing
%>

Open in new window

Hi Carrzkiss,
 
That works perfectly, thank you, (And sorry about the delayed response - my other halfs birthday this weekend, the only problem I have now, is attaching a variable document (CV)  any thoughts on how best to do this?
 
Once again many thanks
try to hard code it.

Example
ObjSendMail.AddAttachment "c:\myweb\somefile.cv"

Add it right above

ObjSendMail.Send

Carrzkiss
I've tried using your example as below, but when I run the script I get the following error -
 
 
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'AddAttachment'
/test2.asp, line 63
 
Where line 63 is "ObjSendMail.AddAttachment = Attach"
Attach is a reference to line 49 "Attach=(jobapplication("JBAPCV"))"
 
Stuck on this?
 
 Thanks again mate
 

<%
Dim ObjSendMail
Dim iConf
Dim Flds
     
Set ObjSendMail = Server.CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
     
Flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
     
'**** Path below may need to be changed if it is not correct
Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"
Flds.Update
' list all varialbes here, give them a "Name" to be used in your TextBody, ReplyTo, From and any other area
PName=(jobapplication("JBAPName"))
URLShort=(Recordset1("JBSURLShort"))
CovLetter=(jobapplication("JBAPCoveringLetter"))
ReplyMail=(Recordset1("JBSNoReplyEmail"))
PEmail=(jobapplication("JBAPEmail"))
Attach=(jobapplication("JBAPCV"))
 
' you do not really have to use:   (Recordset1.Fields.Item("JBSNoReplyEmail").Value).
' this can be cut down by doing this: (Recordset1("JBSNoReplyEmail"))
' They both do the same exact thing. This is usually a Generated Code that does it like that. Dreamweaver is one of them.
     
Set ObjSendMail.Configuration = iConf
ObjSendMail.To = "gareth@hampshirejobsonline.co.uk"
ObjSendMail.Subject = "this is the subject"
ObjSendMail.From = ReplyMail
ObjSendMail.ReplyTo = PEmail     
' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = "Please find the application of " & PName & " for your vacancy advertised on " & URLShort & "" & vbCRLF & "" & vbCRLF & CovLetter
ObjSendMail.AddAttachment = Attach
ObjSendMail.Send
     
Set ObjSendMail = Nothing
Response.Redirect "index.asp"
%>

Open in new window

you will have to do it like this.

Attach=(jobapplication("JBAPCV"))   ' This holds just the name of the file.cv ONLY no path

Change this
ObjSendMail.AddAttachment = Attach

To this
' We have to add in the fully qualified path and remove the = sign for this to work properly.
ObjSendMail.AddAttachment  "C:\path to location\of file\"&Attach&""

This is tested. And works right well.
Carrzkiss
There is a little bit of a problem, in that my site has been running since January and the file upload script has been uploading the path, so my directory address looks like this -
C:\path to location\of file\
and the variable looks like this -
/cvs/document.doc
Anyway of getting rid og the "/cvs/"  part of the variable using asp, rather than completely changing the database?
Sorry about this and
Thanks
 
replace
ObjSendMail.AddAttachment  "C:\path to location\of file\"&Attach&""

with

ObjSendMail.AddAttachment  "C:\path to location\of file\"&replace(Attach,"/cvs/","")&""

That should do it (Tested, Works)

Carrzkiss
I really appreciate your help here, but again I'm really struggleng with this, on my server the address to the file is -
D:\home\JobBoards\jobboardname.co.uk\htdocs\CVS\variablefile.doc
I slightly amended your code to read the following -
ObjSendMail.AddAttachment "D:\home\JobBoards\jobboardname.co.uk\htdocs"&replace(Attach,"/","\")&""""
but now I get the following message -
 
 
CDO.Message.1 error '8007007b'
The filename, directory name, or volume label syntax is incorrect.
/test2.asp, line 63
Where line 63 is the the line of code above.
 
Help... I must be doing something incredibly wrong?
 
thank you
Remove 2 sets of the Quotes at the end of the string

From this
ObjSendMail.AddAttachment "D:\home\JobBoards\jobboardname.co.uk\htdocs"&replace(Attach,"/","\")&""""

To this

ObjSendMail.AddAttachment "D:\home\JobBoards\jobboardname.co.uk\htdocs"&replace(Attach,"/","\")&""

Carrzkiss
Eureka!! Thank you mate that is perfect, I've just got one last question (Please) now, how do I change this so that it uses the servers outgoing mail server rather than IIS, so that it is bein authenticated?
Thanks Carrzkiss, as usual you are a star
 
GTN
Change the code to suite your needs.

Carrzkiss
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath ("Q_24413297.mdb") & ";"
objConn.Open
 
getS = Request.QueryString("ID")
Set objRs=Server.CreateObject("ADODB.RecordSet")
getSQL = "SELECT JBSSiteID, JBSMetaTitle, JBSLogo, JBSMetaKeywords, JBSMetaDescription, JBSURLShort, JBSNoReplyEmail, JBSURL, JBAPCV FROM JBSite WHERE JBSSiteID="& getS &""
objRs.Open getSQL, objConn, 1, 1, 1
 
 
FromAddress = (objRs("JBSNoReplyEmail"))
 
 
Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message") 
     
'This section provides the configuration information for the remote SMTP server.
     
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="smtp.domain.net"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
     
' If your server requires outgoing authentication uncomment the lines bleow and use a valid email address and password.
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="somemail@yourserver.com"
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="yourpassword"
     
ObjSendMail.Configuration.Fields.Update
PName=(jobapplication("JBAPName"))
URLShort=(Recordset1("JBSURLShort"))
CovLetter=(jobapplication("JBAPCoveringLetter"))
ReplyMail=(Recordset1("JBSNoReplyEmail"))
PEmail=(jobapplication("JBAPEmail"))
Attach=(jobapplication("JBAPCV"))
    
'End remote SMTP server configuration section==
     
ObjSendMail.To = "gareth@domain.co.uk"
ObjSendMail.Subject = "subject goes here"
ObjSendMail.From = ReplyMail
ObjSendMail.ReplyTo = PEmail 
     
' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = "Sending of file G:\InetPub\wwwroot\EE\Q_24413297"&replace(Attach,"/","\")&""
ObjSendMail.AddAttachment "D:\home\JobBoards\jobboardname.co.uk\htdocs"&replace(Attach,"/","\")&""
 
     
ObjSendMail.Send
     
Set ObjSendMail = Nothing 
'Response.Redirect "advertisefree.html" 'change this to the redirect URL if you need one
Recordset1.Close()
Set Recordset1 = Nothing
response.Write"Message sent successfully"
%>

Open in new window

Thanks mate, on the off chance, I can't just change a little of the code we have already (you) written (before i mentioned connecting to an external SMTP) can we?
 
Thanks
try this.
Change line 19
To the domain of your Mail Server.

Let me know if it works?

Carrzkiss
<%
Dim ObjSendMail
Dim iConf
Dim Flds
     
Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message") 
'Set iConf = CreateObject("CDO.Configuration")
'Set Flds = iConf.Fields
     
'Flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
     
'**** Path below may need to be changed if it is not correct
'Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"
'This section provides the configuration information for the remote SMTP server.
     
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="smtp.domain.net"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
     
' If your server requires outgoing authentication uncomment the lines bleow and use a valid email address and password.
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="somemail@yourserver.com"
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="yourpassword"
 
'Flds.Update
' list all varialbes here, give them a "Name" to be used in your TextBody, ReplyTo, From and any other area
PName=(jobapplication("JBAPName"))
URLShort=(Recordset1("JBSURLShort"))
CovLetter=(jobapplication("JBAPCoveringLetter"))
ReplyMail=(Recordset1("JBSNoReplyEmail"))
PEmail=(jobapplication("JBAPEmail"))
Attach=(jobapplication("JBAPCV"))
 
' you do not really have to use:   (Recordset1.Fields.Item("JBSNoReplyEmail").Value).
' this can be cut down by doing this: (Recordset1("JBSNoReplyEmail"))
' They both do the same exact thing. This is usually a Generated Code that does it like that. Dreamweaver is one of them.
     
Set ObjSendMail.Configuration = iConf
ObjSendMail.To = "gareth@domain.co.uk"
ObjSendMail.Subject = "this is the subject"
ObjSendMail.From = ReplyMail
ObjSendMail.ReplyTo = PEmail     
' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = "Please find the application of " & PName & " for your vacancy advertised on " & URLShort & "" & vbCRLF & "" & vbCRLF & CovLetter
ObjSendMail.AddAttachment = Attach
ObjSendMail.Send
     
Set ObjSendMail = Nothing
Response.Redirect "index.asp"
%>

Open in new window

Line 18
Needs to be change, not 19
Sorry mate - got this -
 
Microsoft VBScript compilation error '800a0411'
Name redefined
/test3.asp, line 34 Dim ObjSendMail
remove the duplicate
Dim ObjSendMail
Ummm,... gives me this, I really appreciate the amount of time you are giving me, and dont want to take advantage, but I also have a small additional problem, in that I have (Using the IIS Server version) added  -
ConkerEmail=(emailApplication("JBAConkersEmail"))
 
ObjSendMail.Bcc = ConkerEmail
This works fine if ConkerEmail is not null, but a lot of the time it will be, is there a way of saying, if not null BCC = else ""
Thanks mate
 
Hi Mate, not sure whether you are there are not, but let me try and explain a little better, I think what I am looking for is a bit of code that sais -
IF (emailApplication("JBAConkersEmail")) <>"" then ObjSendMail.Bcc = ConkerEmail else
Disregard ObjSendMail.Bcc
Not sure whether this is possible or not, just for confirmation purposes, I have attached the latest code..
Thank you

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/recruta2.asp" -->
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows
 
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_recruta2_STRING
Recordset1_cmd.CommandText = "SELECT JBSSiteID, JBSMetaTitle, JBSLogo, JBSMetaKeywords, JBSMetaDescription, JBSURLShort, JBSNoReplyEmail, JBSURL FROM dbo.JBSite WHERE JBSSiteID = 30" 
Recordset1_cmd.Prepared = true
 
Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<%
Dim emailApplication
Dim emailApplication_cmd
Dim emailApplication_numRows
 
Set emailApplication_cmd = Server.CreateObject ("ADODB.Command")
emailApplication_cmd.ActiveConnection = MM_recruta2_STRING
emailApplication_cmd.CommandText = "SELECT JBAPID, JBAPAdvertID, JBAPEmployeeID, JBAPSiteID, JBAPName, JBAPCoveringLetter, JBAPCV, JBAPDate, JBAPEmail, JBATitle, JBAID, JBAConkersEmail, JBEID, JBEUsername, JBEName FROM dbo.JBApplication, dbo.JBAdvert, dbo.JBEmployee WHERE JBAID = JBAPAdvertID AND JBEID = JBAPEmployeeID AND JBAPID = '2931'" 
emailApplication_cmd.Prepared = true
 
Set emailApplication = emailApplication_cmd.Execute
emailApplication_numRows = 0
%>
<%
Dim ObjSendMail
Dim iConf
Dim Flds
     
Set ObjSendMail = Server.CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
     
Flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
     
'**** Path below may need to be changed if it is not correct
Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"
Flds.Update
' list all varialbes here, give them a "Name" to be used in your TextBody, ReplyTo, From and any other area
APName=(emailApplication("JBAPName"))
URLShort=(Recordset1("JBSURLShort"))
APCovLetter=(emailApplication("JBAPCoveringLetter"))
ReplyMail=(Recordset1("JBSNoReplyEmail"))
APEmail=(emailApplication("JBAPEmail"))
Attach=(emailApplication("JBAPCV"))
RECEmail=(emailApplication("JBEUsername"))
ConkerEmail=(emailApplication("JBAConkersEmail"))
JobTitle=(emailApplication("JBATitle"))
RecName=(emailApplication("JBEName"))
 
' you do not really have to use:   (Recordset1.Fields.Item("JBSNoReplyEmail").Value).
' this can be cut down by doing this: (Recordset1("JBSNoReplyEmail"))
' They both do the same exact thing. This is usually a Generated Code that does it like that. Dreamweaver is one of them.
     
Set ObjSendMail.Configuration = iConf
ObjSendMail.To = RECEmail
ObjSendMail.Bcc = ConkerEmail
ObjSendMail.Subject = "Application for " & JobTitle & " from " & URLShort
ObjSendMail.From = ReplyMail
ObjSendMail.ReplyTo = APEmail     
' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = "Dear " & RecName & "" & vbCRLF & "" & vbCRLF &"Please find the application of " & APName & " for your vacancy advertised on " & URLShort & "" & vbCRLF & "" & vbCRLF & APCovLetter
ObjSendMail.AddAttachment "D:\home\JobBoards\jobboard.co.uk\htdocs"&replace(Attach,"/","\")&""
ObjSendMail.Send
     
Set ObjSendMail = Nothing
Response.Redirect "index.asp"
%>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
<%
emailApplication.Close()
Set emailApplication = Nothing
%>

Open in new window

Or perhaps, is there a way of including the BCC value as part of the To, something like -
RECEmail=(emailApplication("JBEUsername"));(emailApplication("JBAConkersEmail"))

?
Thanks mate
ASKER CERTIFIED SOLUTION
Avatar of Wayne Barron
Wayne Barron
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
fantastic thanks mate - you truely are an expert
A true expert - and friendly too
:)
You are very welcome.
This was fun and a learning experiance for me as well.
I am helped someone else yesterday as well, using your code as well as some that I had
To make up to work for them.

I learned a lot with using the CDOSYS component.
And it is going to prove to be really handy with the project that I am working on now.
That needs to be released by next week. (My bread and butter so to speak)
Without it, I am broke....

Anyway.
Working with you on this project has helped me to learn a lot about how to
Work with CDOSYS and make it work the way that it needs to work in order to accomplish our needs.

Awesome Knowledge.
Love It.

Take Care Gareth
Wayne
I really hope your project goes well, I'm sure it will, if I can be of any help mate, let me know, I'm right that you are UK based am I?
I am US.
Live in NC on the East Coast.
Once I start making some money of from this project that I am doing
I am going to relocate to another State,
And may have plans of getting a place in Australia.
(Love the way Australian Women talk... Melts you)

The UK, I use to deal with some vendors there back in the late 90's when
I own and operated a local Music Store. (I miss that place)
I had 2 vendors that I dealt with Imports. (As soon as I would get them in the door, they went out the door).
Maybe sometime in the near future I will be able to open my store again.
There is just something about having your own business like that, you know?

Back to the grinding board.
I will send you over an e-mail with the site link once it is done.
Right now, there is just a place holder for the site, with a big pulgy Construction Guy... ;~)

Have a good one Gareth.
Wayne