ASP Kan ikke sende mail gennem Exchange (CDO)
Jeg har to scripts, der begge sender mails gennem en exchange server.Det ene er ASP, der kører via en IIS 7, det andet er et Powershell script.
Powershell scriptet virker, det gør ASP scriptet ikke.
Men hvor ligger forskellen? Hvad gør jeg forkert i ASP?
Jeg ved at afsender-adresse, servernavn, serverport, brugernavn og kodeord osv. er korrekt, for det er det samme jeg bruger i Powershell...
ASP Script
On Error Resume Next
Set cdoMail = CreateObject("CDO.Message")
Set cdoConfig = CreateObject("CDO.Configuration")
Set Flds = cdoConfig.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "80.80.80.80"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Svar_Ikke@domain.dk"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "passw0rd"
.Update
End With
With cdoMail
Set .Configuration = cdoConfig
.To = "mig@mitdomain.dk"
.From = "svar_ikke@domain.dk"
.Subject = "test"
.TextBody = "Here is the message"
.Send
End With
Set cdoMail = Nothing
Set cdoConfig = Nothing
Set Flds = Nothing
If Err Then Response.Write vbCrLf & vbCrLf & "<h1>SendMail Failed</h1>Error code: <strong>" & Err.Number & "</strong>" & vbCrLf & "Error description: " & vbCrLf & "<strong>" & Err.Description & "</strong>"
On Error Goto 0
Powershell script
$EmailFrom = "svar_ikke@domain.dk"
$EmailTo = "mig@mitdomain.dk"
$Subject = "test"
$Body = "Here is the message"
$SMTPServer = "80.80.80.80"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
#$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("Svar_Ikke@domain.dk", "passw0rd");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)