Molto spesso si ha la necessità di invare report o file di log in automatico dopo l’esecuzione di un processo.

Il seguente script descrive come inviare una mail con allegato.

I vantaggi di questo script sono:

  • Non necessita l’installazione di software di terze parti.
  • Non occorre un client di posta configurato sul pc che esegue lo script.
  • Non serve un server SMTP installato sul pc che esegue lo script.
  • Consente l’invio di allegati.
  • Consente l’utilizzo di qualsiasi server SMTP con o senza autenticazione.

Const cdoSendUsingPickup = 1 ‘Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 ‘Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 ‘Do not authenticate
Const cdoBasic = 1 ‘basic (clear-text) authentication
Const cdoNTLM = 2 ‘NTLM

Set objMessage = CreateObject(“CDO.Message”)
objMessage.Subject = “Oggetto del messaggio”
objMessage.From = “””Nome visulaizzato“” <Email Mittente>”
objMessage.To = “Email Destinatario
objMessage.TextBody = “Corpo del messaggio
objMessage.AddAttachment “Percorso allegato comprensivo di nome ed estensione dello stesso

‘==This section provides the configuration information for the remote SMTP server.

objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2

‘Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “Indirizzop Server SMTP

‘Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”) = cdoBasic

‘Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendusername”) = “User Name SMTP

‘Your password on the SMTP server
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendpassword”) = “Password SMTP

‘Server port (typically 25)
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25

‘Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpusessl”) = False

‘Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”) = 60

objMessage.Configuration.Fields.Update

‘==End remote SMTP server configuration section==

objMessage.Send

Copiare questo script, modificandolo opportunamente, in un file di testo e modificare l’estensione in .vbs

Follow

© 2023 N.S. S.a.s. di Mangogna Sergio & C.

HOME         PRODOTTI         SOLUZIONI         FAQ         LINKS         DOWNLOADS         CONTATTI

P.zza Cav. di Vitt. Veneto, 28
20090 Buccinasco (MI)

P.IVA 11768670157

info@nssas.it

+39 02 36 55 1606