By 17 Gennaio 2014 0 Comments

Invio di un messaggio con CDO e gestione dell’errore

Il seguente script in ASP mostra come inviare un messaggio e-mail da un server IIS.
Il messaggio è generato con CDO, utilizza un mailserver esterno (quindi non localhost) e ha una gestione in caso di errore :

<%
On Error Resume Next

set objcdoconf = server.createobject (“cdo.configuration”)
with objcdoconf
.fields(“https://schemas.microsoft.com/cdo/configuration/smtpserver”) = “mail.sito.net”
.fields(“https://schemas.microsoft.com/cdo/configuration/smtpserverport”) = “25”
.fields(“https://schemas.microsoft.com/cdo/configuration/sendusing”) = “2”
.fields(“https://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”) = “60”
.fields.update
end with

set objmail = server.createobject(“cdo.message”)
set objmail.configuration = objcdoconf

objmail.subject=”CIAO”
objmail.from=”noreply@sito.net”
objmail.to=”destinatario@sito.it”
objmail.textbody=”TEST”
objmail.send()

set objcdoconf = nothing
set objmail = nothing

If Err.Number = 0 Then
Response.write(“OK”)
Else
Response.write(“FAIL”)
End If%>

About the Author:

shared on wplocker.com