mercoledì 19 giugno 2013

Centralino IP PBX su Windows - 3CX Phone System which links here: http://www.3cx.it/centralino/index.html

RSS Feed RSS Feed

Login

Newsletter Newsletter

Registrati

RisorseScript

 

31

Con il seguente script è possibile inviare un'email tramite script utilizzando CDONTS.

 

'--------------------------------------------------
'
' Sends email from the local SMTP service using CDONTS objects
'
' Usage:
' sendmail [-smtp <server>] [-port <port>] [-auth <0=None, 1=Basic, 2=NTLM>] [-user <user>] [-pass <password>]
' -t <to> -f <from> -s "<subject>" -b "<message>" -a "<attachment1>,<attachment2>,..,<attachmentN>"
' sendmail [-help|-?]
'
'--------------------------------------------------

Option Explicit
On Error Resume Next

Dim oArgs, ArgNum
Dim strServer, intPort, intAuth, strUser, strPass, strTo, strFrom, strSubject, strBody, strAttachments
Dim arrAttachments, strAttachment
Dim strSch, objConfig, objMessage

Set oArgs = WScript.Arguments
ArgNum = 0
strServer = "localhost"
intPort = 25
intAuth = 0

While ArgNum < oArgs.Count
    Select Case LCase(oArgs(ArgNum))
        Case "-smtp"
            ArgNum = ArgNum + 1
            strServer = oArgs(ArgNum)
        Case "-port"
            ArgNum = ArgNum + 1
            intPort = oArgs(ArgNum)
        Case "-auth"
            ArgNum = ArgNum + 1
            intAuth = oArgs(ArgNum)
        Case "-user"
            ArgNum = ArgNum + 1
            strUser = oArgs(ArgNum)
        Case "-pass"
            ArgNum = ArgNum + 1
            strPass = oArgs(ArgNum)
        Case "-to","-t":
            ArgNum = ArgNum + 1
            strTo = oArgs(ArgNum)
        Case "-from","-f":
            ArgNum = ArgNum + 1
            strFrom = oArgs(ArgNum)
        Case "-subject","-s":
            ArgNum = ArgNum + 1
            strSubject = oArgs(ArgNum)
        Case "-body","-b":
            ArgNum = ArgNum + 1
            strBody = oArgs(ArgNum)
        Case "-attachment","-a":
            ArgNum = ArgNum + 1
            strAttachments = oArgs(ArgNum)
        Case "-help","-?":
            Call DisplayUsage
        Case Else:
            Call DisplayUsage
    End Select
    ArgNum = ArgNum + 1
Wend

WScript.Echo strAttachments

If oArgs.Count=0 Or strTo="" Or strFrom="" Or _
            strSubject="" Or strBody="" Then
        Call DisplayUsage
Else
    strSch = "http://schemas.microsoft.com/cdo/configuration/"

    Set objConfig = CreateObject("CDO.Configuration")

    With objConfig.Fields
    .Item(strSch & "sendusing") = 2 ' cdoSendUsingPort
    .Item(strSch & "smtpauthenticate") = intAuth
    .Item(strSch & "smtpserver") = strServer
    .Item(strSch & "smtpserverport") = intPort

    If intAut = 1 Then
        .Item(strSch & "sendusername") = strUser
        .Item(strSch & "sendpassword") = strPass
    End If
    .update
End With


Set objMessage = CreateObject("CDO.Message")

With objMessage
    Set .Configuration = objConfig
    .From = strFrom
    .To = strTo
    .Subject = strSubject
    .TextBody = strBody

    IF strAttachments <> "" Then
        arrAttachments = Split(strAttachments, ",", -1, 1)
        For Each strAttachment in arrAttachments
            .AddAttachment(strAttachment)
        Next
        Set arrAttachments = Nothing
    End If
    .Send
End With

    Set objMessage = Nothing
    Set objConfig = Nothing
End If

' Display the usage for this script
Sub DisplayUsage
    WScript.Echo "Usage:" & _
        Chr(13) & Chr(13) & _
        "sendmail [-smtp <server>] [-port <port>] [-auth <0=None, 1=Basic, 2=NTLM>] [-user <user>] [-pass <password>]" & _
        Chr(13) & _
        " -t <to address> -f <from address>" & _
        Chr(13) & _
        " -s " & Chr(34) & "<subject>" & Chr(34) & " -b " & Chr(34) & "<message>" & Chr(34) & _
        Chr(13) & _
        " -a " & Chr(34) & "<attachment1>,<attachment2>,..,<attachmentN>" & Chr(34) & _
        Chr(13) & Chr(13) & _
        "sendmail [-help|-?]"
    WSCript.Quit
End Sub


Scritto in: Script
AZIONI: E-mail | Permalink |
CONDIVIDI: del.icio.us   Facebook   Digg   Google   Live Bookmarks   Newsvine   StumbleUpon   Technorati   Yahoo   DotNetKicks
blog comments powered by Disqus

  Le ultime notizie dal mondo
18/06/2013 - Infor ha acquistato Tdci
Arrivano applicazioni per la gestione della configurazione dei prodotti per manufacturing e distribution. 18 Giugno 2013
18/06/2013 - Datagate: ora gli It player chiedono di poter parlare
Mentre continuano le rivelazioni sui controlli delle agenzie americane sulle attività dei cittadini, Apple, Facebook, Google e Microsoft chiedono di poter rendere pubbliche le rich...
17/06/2013 - Con 808 PureView Nokia dà l'addio definitivo a Symbian
Come anticipato a inizio anno, la stagione estiva segna la fine del percorso Symbian per Nokia. 17 Giugno 2013
17/06/2013 - Wifi libero e domicilio digitale nel Decreto Fare
Obiettivo è rendere davvero libera la connettività wireless liberandola da quei vincoli a cui era stata costretta a soggiacere per anni dopo l'approvazione del decreto Pisanu. In t...
14/06/2013 - Apple tentata da un iPhone sotto i 100 dollari
Voci di agenzia fanno riferimento ad un dispositivo dal costo estremamente contenuto rispetto ai modelli attuali grazie anche alla scelta di materiali plastici. 14 Giugno 2013
  
Copyright 2011 by SysAdmin.it