Oje noch ein Blog Übers Leben, das Universum und den ganzen anderen Rest…

22Sep/110

VBS: Email versenden mit Outlook

Als Parameter kann Empfänger sowie die Antwortadresse angegeben werden. Die eMail Adresse wird auf Format geprüft.

' ################################
'
' SendMail.vbs
'

' Sends an eMail through Microsoft Outlook
'
' Usage: SendMail.vbs recipient@domain.com reply-to-address@domain.com
' 09/22/2011 Daniel Ristic
'
' ################################

If WScript.Arguments.Count < 2 then
WScript.Echo "Usage: SendMail.vbs recipient@domain.com reply-to-address@domain.com"
Else
Set RegEx = New regexp
RegEx.Pattern = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
RegEx.IgnoreCase = true
If RegEx.Test(WScript.Arguments.Item(0)) <> true OR RegEx.Test(WScript.Arguments.Item(1)) <> true Then
WScript.Echo "Error: Invalid email addresses. Please check format."
Else
Call SendOutlookEmail(WScript.Arguments.Item(0),WScript.Arguments.Item(1))
End If
End If

Function SendOutlookEmail(strTo, strReplyTo)

' Create a new Outlook Object
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
' ################################

' Get Timezone Name
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone")

For Each objItem in colItems
Timezone = objItem.Caption
Next

' Send Email
With OutlookMail
.BodyFormat = 1
.To = strTo
.Subject = Date() & ";" & Time() & ";" & Timezone
.Body = Date() & vbCrLf & Time() & vbCrLf & Timezone
.replyRecipients.Add(strReplyTo)
.Send
End With

End Function

Kommentare (0) Trackbacks (0)

Zu diesem Artikel wurden noch keine Kommentare geschrieben.


Leave a comment

(required)

Noch keine Trackbacks.