[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 681
  • Last Modified:

Adding smtp authentication to asp form mailer script...

Hi there, how can I add smtp authentication to this form so that I can utilize an external smtp server with the below credentials?

server: smtp.eggster.com
user: hotmail@eggster.com
pass: egg

--

<%
dim myMailMessage

'first send an e-mail to you
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Mailed received from " & request.form("firstname") & " " & request.form("lastname")
myMail.From=request.form("email")
myMail.To="eggster@eggster.com"

myMailMessage = "First Name: " & request.form("firstname") & vbcrlf
myMailMessage = myMailMessage & "Last Name: " & request.form("lastname") & vbcrlf
myMailMessage = myMailMessage & "Email: " & request.form("email") & vbcrlf
myMailMessage = myMailMessage & "Phone: " & request.form("phone") & vbcrlf
myMailMessage = myMailMessage & "Comments: & request.form("comments")

myMail.TextBody = myMailMessage
myMail.Send

'next, send an e-mail to the user
myMail.Subject="Thank you"
myMail.From="eggster@eggster.com"
myMail.To=request.form("email")
myMail.TextBody = "Thank you - we received your message"
myMail.Send

set myMail=nothing

response.redirect "thanks.html"

%>

thanks!
0
eggster34
Asked:
eggster34
  • 11
  • 6
1 Solution
 
samic400Commented:
Try this:

<%
Const cdoSendUsingMethod        = _
      "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort          = 2
Const cdoSMTPServer             = _
      "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort         = _
      "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout  = _
      "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate       = _
      "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic                  = 1
Const cdoSendUserName           = _
      "http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword           = _
      "http://schemas.microsoft.com/cdo/configuration/sendpassword"

Dim objConfig  ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields     ' As ADODB.Fields

' Get a handle on the config object and it's fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields

' Set config fields we care about
With Fields
      .Item(cdoSendUsingMethod)       = cdoSendUsingPort
      .Item(cdoSMTPServer)            = "smtp.eggster.com"
      .Item(cdoSMTPServerPort)        = 25
      .Item(cdoSMTPConnectionTimeout) = 10
      .Item(cdoSMTPAuthenticate)      = cdoBasic
      .Item(cdoSendUserName)          = "hotmail@eggster.com"
      .Item(cdoSendPassword)          = "egg"

      .Update
End With

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

Set objMessage.Configuration = objConfig

dim myMailMessage

'first send an e-mail to you
objMessage.Subject="Mailed received from " & request.form("firstname") & " " & request.form("lastname")
objMessage.From=request.form("email")
objMessage.To="eggster@eggster.com"

myMailMessage = "First Name: " & request.form("firstname") & vbcrlf
myMailMessage = myMailMessage & "Last Name: " & request.form("lastname") & vbcrlf
myMailMessage = myMailMessage & "Email: " & request.form("email") & vbcrlf
myMailMessage = myMailMessage & "Phone: " & request.form("phone") & vbcrlf
myMailMessage = myMailMessage & "Comments: & request.form("comments")

objMessage.TextBody = myMailMessage
objMessage.Send

'next, send an e-mail to the user
objMessage.Subject="Thank you"
objMessage.From="eggster@eggster.com"
objMessage.To=request.form("email")
objMessage.TextBody = "Thank you - we received your message"
objMessage.Send

Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing

response.redirect "thanks.html"

%>
0
 
eggster34Author Commented:
still get the same error

CDO.Message.1 error '80040220'

The "SendUsing" configuration value is invalid.

/mail.asp, line 57
0
 
samic400Commented:
<!--
    METADATA
    TYPE="typelib"
    UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"  
    NAME="CDO for Windows 2000 Library"
-->  
<%
Const cdoSendUsingPort          = 2
Const cdoSMTPServer             = _
      "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort         = _
      "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout  = _
      "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate       = _
      "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic                  = 1
Const cdoSendUserName           = _
      "http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword           = _
      "http://schemas.microsoft.com/cdo/configuration/sendpassword"

Dim objConfig  ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields     ' As ADODB.Fields

' Get a handle on the config object and it's fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields

' Set config fields we care about
With Fields
      .Item(cdoSendUsingMethod)       = cdoSendUsingPort
      .Item(cdoSMTPServer)            = "smtp.eggster.com"
      .Item(cdoSMTPServerPort)        = 25
      .Item(cdoSMTPConnectionTimeout) = 10
      .Item(cdoSMTPAuthenticate)      = cdoBasic
      .Item(cdoSendUserName)          = "hotmail@eggster.com"
      .Item(cdoSendPassword)          = "egg"

      .Update
End With

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

Set objMessage.Configuration = objConfig

dim myMailMessage

'first send an e-mail to you
objMessage.Subject="Mailed received from " & request.form("firstname") & " " & request.form("lastname")
objMessage.From=request.form("email")
objMessage.To="eggster@eggster.com"

myMailMessage = "First Name: " & request.form("firstname") & vbcrlf
myMailMessage = myMailMessage & "Last Name: " & request.form("lastname") & vbcrlf
myMailMessage = myMailMessage & "Email: " & request.form("email") & vbcrlf
myMailMessage = myMailMessage & "Phone: " & request.form("phone") & vbcrlf
myMailMessage = myMailMessage & "Comments: & request.form("comments")

objMessage.TextBody = myMailMessage
objMessage.Send

'next, send an e-mail to the user
objMessage.Subject="Thank you"
objMessage.From="eggster@eggster.com"
objMessage.To=request.form("email")
objMessage.TextBody = "Thank you - we received your message"
objMessage.Send

Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing

response.redirect "thanks.html"

%>
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
eggster34Author Commented:
sorry that's my bad. re-adapting the script.
0
 
eggster34Author Commented:
I get this error now:

ADODB.Fields error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/mail.asp, line 27

it points to the line where we define the smtp server :(
0
 
eggster34Author Commented:
after I added

<!--
    METADATA
    TYPE="typelib"
    UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"  
    NAME="CDO for Windows 2000 Library"
-->  

I get: Microsoft VBScript runtime error '800a0411'

Name redefined: 'cdoSendUsingPort'

/mail.asp, line 8

do you have a way of testing this instead of doing it via trial & error? :(
0
 
samic400Commented:
ok - change this section:
With Fields
      .Item(cdoSendUsingMethod)       = cdoSendUsingPort
      .Item(cdoSMTPServer)            = "smtp.eggster.com"
      .Item(cdoSMTPServerPort)        = 25
      .Item(cdoSMTPConnectionTimeout) = 10
      .Item(cdoSMTPAuthenticate)      = cdoBasic
      .Item(cdoSendUserName)          = "hotmail@eggster.com"
      .Item(cdoSendPassword)          = "egg"

      .Update
End With

with this:

With Fields
      .Item(cdoSendUsingMethod)       = 2
      .Item(cdoSMTPServer)            = "smtp.eggster.com"
      .Item(cdoSMTPServerPort)        = 25
      .Item(cdoSMTPConnectionTimeout) = 10
      .Item(cdoSMTPAuthenticate)      = 1
      .Item(cdoSendUserName)          = "hotmail@eggster.com"
      .Item(cdoSendPassword)          = "egg"

      .Update
End With
0
 
eggster34Author Commented:
should I keep this part or not?

<!--
    METADATA
    TYPE="typelib"
    UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"  
    NAME="CDO for Windows 2000 Library"
-->  
0
 
eggster34Author Commented:
if I do not include the part above, I get the exact same error:

ADODB.Fields error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/mail.asp, line 27

when I include it, I get the exact same error:

Microsoft VBScript runtime error '800a0411'

Name redefined: 'cdoSendUsingPort'

/mail.asp, line 8
0
 
samic400Commented:
Yes - keep it in -

tell me exactly what line 8 is...
0
 
eggster34Author Commented:
this is what my code looks like, so the 8th line is Const cdoSendUsingPort          = 2 in this case?



<!--
    METADATA
    TYPE="typelib"
    UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"  
    NAME="CDO for Windows 2000 Library"
-->  
<%
Const cdoSendUsingPort          = 2
Const cdoSMTPServer             = _
      "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort         = _
      "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout  = _
      "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate       = _
      "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic                  = 1
Const cdoSendUserName           = _
      "http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword           = _
      "http://schemas.microsoft.com/cdo/configuration/sendpassword"
0
 
eggster34Author Commented:
I'm running this on windows 2003 / IIS 6.0 by the way.
0
 
samic400Commented:
Take this line -
Const cdoSendUsingPort          = 2

out of the page and try again.
0
 
eggster34Author Commented:
and now it goes to the next line

Microsoft VBScript runtime error '800a0411'

Name redefined: 'cdoSMTPServer'

/mail.asp, line 8
0
 
eggster34Author Commented:
I actually made it work by playing around with the code, this is the working version.

<%
Const cdoSendUsingMethod       = "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort         = 2
Const cdoSMTPServer            = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort        = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout = "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate      = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic                 = 1
Const cdoSendUserName          = "http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword          = "http://schemas.microsoft.com/cdo/configuration/sendpassword"

Dim objConfig  ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields     ' As ADODB.Fields

' Get a handle on the config object and it's fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields

' Set config fields we care about
With Fields
        .Item(cdoSendUsingMethod)       = cdoSendUsingPort
        .Item(cdoSMTPServer)            = "mail.eggster.com"
        .Item(cdoSMTPServerPort)        = 25
        .Item(cdoSMTPConnectionTimeout) = 10
        .Item(cdoSMTPAuthenticate)      = cdoBasic
        .Item(cdoSendUserName)          = "eggster@eggster.com"
        .Item(cdoSendPassword)          = "eggster34"

.Update
End With

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

Set objMessage.Configuration = objConfig

dim myMailMessage

'first send an e-mail to you
objMessage.Subject="Contact Form"
objMessage.From=request.form("email")
objMessage.To="hotmail@eggster.com"

myMailMessage = "First Name: " & request.form("firstname") & vbcrlf
myMailMessage = myMailMessage & "Last Name: " & request.form("lastname") & vbcrlf
myMailMessage = myMailMessage & "Email: " & request.form("email") & vbcrlf
myMailMessage = myMailMessage & "Phone: " & request.form("phone") & vbcrlf
myMailMessage = myMailMessage & "Comments:" & request.form("comments")

objMessage.TextBody = myMailMessage
objMessage.Send

'next, send an e-mail to the user
objMessage.Subject="Confirmation"
objMessage.From="sentfrom@eggster.com"
objMessage.To=request.form("email")
objMessage.TextBody = "Thank you !"
objMessage.Send

Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing

response.redirect "thankyou.html"

%>
0
 
samic400Commented:
I'm glad you got it working - I hadn't played around with remote smtp before and that is why it was trial and error - the script from the previous question was a local smtp and something i use on a daily basis in a previous question and I knew that would work. good luck!
0
 
eggster34Author Commented:
we spent so much time together, I didn't want to leave the expert with nothing. pls look at my post for the complete solution.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 11
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now