venerdì 12 giugno 2015

Invio email da asp con CDO.Message

Tramite componenti di Microsfot CDO.Message e CDO.Configuration è possibile inviare un email, ad esempio, con parametri SMTP.
Di seguito un esempio di una funzione asp per inviare un email:

function sendEmail()
email_mittente = "someone@example.com"
email_destinatario = "someone@example.com"
email_oggetto = "test object"
email_corpo = "test test body"
email_tipo = ""
set objCDO = Server.CreateObject("CDO.Message")
Set objConfig = Server.createObject ("CDO.Configuration") 
Set Flds = objConfig.Fields
Flds("http://schemas.microsoft.com/cdo/configuration/urlgetlatestversion") = True
Flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
Flds("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.example.com"
Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
Flds("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
Flds("http://schemas.microsoft.com/cdo/configuration/sendusername") = "smtp@example.com"
Flds("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "passexample"
Flds.Update
With objCDO
 Set .Configuration = objConfig
 .From = email_mittente
 .To = email_destinatario
 .Bcc = email_bcc
 .Subject = email_oggetto
 if email_tipo = "html" then
  .HTMLBody = email_corpo
 else
  .TextBody = email_corpo
 end if
 .Send
end with
Set objConfig = Nothing
set objCDO = Nothing
end function