You can use one of the following methods:
- Blat
- Postie
- COM - Howard Bullock's Win32Admin.DLL
- COM (using Outlook)
- COM - Using CDO (Collaborative Data Objects): Thanks Howard!!
- Sendmail() - UDF
Blat (Freeware)
Available from - http://www.blat.net/Usage - File Operations #4
Blat - No file attached..
Code:
BREAK ON
$mailhost = 'smtp.server.com'
$recipient = 'admin@@server.com'
$sender = @userid+'@@server.com'
$mailLine = @ldrive+'Programs\blat.exe - -to $recipient -server $mailhost -subject "No H: drive" '
$mailLine = $mailLine+'-body "H: Drive is not found for @userid (@fullname)" -f $sender -q'
SHELL $mailLine
Blat - File Attached..
Code:
BREAK ON
$Attachment = @scriptdir+"\byname.txt"
$mailhost = 'smtp.server.com' ; -- fill in with your smtp server
$recipient = 'recip@@server.com' ; -- add in your e-mail address
$sender = @userid+'@@server.com'
$mailLine = @ldrive+'Programs\blat.exe $Attachment -to $recipient -server $mailhost -subject "No H: drive" '
$mailLine = $mailLine+'-body "H: Drive is not found for @userid (@fullname)" -f $sender -q'
SHELL $mailLine
POSTIE (Shareware)
Available from - http://www.infradig.com/postie/index.shtmlUsage - Password expiration for a service accountCode:
$mailhost = 'smtp.server.com' ; -- fill in with your smtp server
$recipient = 'recip@@server.com' ; -- add in your e-mail address
$mailLine = @ldrive+'Programs\postie.exe -host:$mailhost -to:$recipient -from:"testroute" '
$mailLine = $mailLine +'-s:"Test Results 1" -file:"byname.txt"'
SHELL $mailLine
Howard Bullock's Win32Admin.DLL
Available at - http://home.comcast.net/~habullock/Code:
Method Email($MailHost, $To, $From, $Subject, $Body)
; Sends an email from your script.
; Be sure to double the "@" in the email address.
$Win32Admin = createobject("Win32Admin")
$mailhost = 'mailhost.xyz.com'
$to = 'habullock@@comcast.net'
$from = 'habullock@@comcast.net'
$subject = 'Test Message'
$body = 'Email from KiXtart is great!'
if $Win32Admin.Email($mailhost, $to, $from, $subject, $body)
? ? "Email to " + $to + " sent."
?
else
? ? "Email Failed! @serror"
?
endif
COM (Outlook)
Usage - Tester needed - Outlook and Outlook Express AutomationCode:
break on
$Root = CreateObject("Outlook.Application")
$MailItem = $Root.CreateItem(0)
$MailItem.Importance = 1
; - 2 high importance
; - 1 normal importance
; - 0 low importance
$MailItem.Subject = "Automation Test"
$MailItem.To = "user@@server.com"
$MailItem.Body = "Test info"
IF EXIST("C:\errorlog.txt")
$MailItem.Attachments.Add("C:\errorlog.txt")
ENDIF
$MailItem.Send
$Root = 0
Ok.. I want to send two attachments in Outlook..
Thanks cmarti Two attachments in an email sent from kix..
This assumes that C:\errorlog.txt and C:\secondlog.txt exist
Code:
break on
$Root = CreateObject("Outlook.Application")
$MailItem = $Root.CreateItem(0)
$MailItem.Importance = 1
; - 2 high importance
; - 1 normal importance
; - 0 low importance
$MailItem.Subject = "Automation Test"
$MailItem.To = "user@@server.com"
$MailItem.Body = "Test info"
$MailItem.Attachments.Add("C:\errorlog.txt")
$MailItem.Save
$MailItem.Attachments.Add("C:\secondlog.txt")
$MailItem.Send
$Root = 0
COM - Using CDO (Collaborative Data Objects)
Installing CDO for NTS
Code:
break ON
$= SetOption("WrapAtEol","On")
break on
$objCDO = CreateObject("CDONTS.NewMail")
IF @error <> 0
?@error " CDO not found"
SLEEP 2
EXIT 1
ENDIF
$objCDO.From = "sender@@server.com"
$objCDO.To = "recipent@@secondserver.com"
$objCDO.Subject = "Software Notification for PC"
$objCDO.Body = "More Testing"
$objCDO.BodyFormat = 0
$objCDO.MailFormat = 0
$objCDO.Send
$objCDO = 0
Software Requirements
The dynamic-link libraries for CDO 1.2.1 (CDO.DLL) and CDO 1.2.1 Rendering (CDOHTML.DLL) are MAPI client object libraries. As such, they require MAPI (the version of MAPI32.DLL installed with Microsoft® Exchange Server version 5.0, or above) and service providers—for example, the same service providers as with Microsoft Exchange Server. CDOHTML.DLL and CDO.DLL are included with Microsoft Exchange Server and are installed on the server when the installation option Active Server Components is selected. CDO 1.2.1 Rendering (CDOHTML.DLL) is intended for server-side use only.
Microsoft® Outlook™ 98 installs the CDO 1.2.1 libraries. To enable client applications to use CDO 1.2.1, install Microsoft Outlook 98. For server applications, install Microsoft Exchange Server version 5.5.
Note CDO works with Microsoft Outlook, but CDO.DLL is not installed with the Microsoft Outlook 97 setup program.
Using SendMail - Sendmail() - send mail with telnet
CDO For XP Systems (Update) > Thanks Ceej Sending Email using COM calls to CDO in KiX.:
Code:
$objEmail=CreateObject('CDO.Message')
IF @ERROR <> 0
?'CDO is not found - Please install First.'
SLEEP 2
EXIT
ENDIF
$objEmail.From='user@@company.com'
$objEmail.To='user@@company.com'
$objEmail.Subject='subject'
$msweb='http://schemas.microsoft.com/cdo/configuration/'
$smtp='smtp.company.com'
$objEmail.Textbody='The User: '+@userid+' on Worksation: '+@wksta+' could not get to subject'
;$objEmail.AddAttachment ("C:\Somedir\somefile.txt") ;Attach a File
$objEmail.Configuration.Fields.Item($msweb+'sendusing').value=2
$objEmail.Configuration.Fields.Item($msweb+'smtpserver').value=$smtp
$objEmail.Configuration.Fields.Item($msweb+'smtpserverport').value=25
$objEmail.Configuration.Fields.Update
$objEmail.Send
?"ERROR @ERROR: @SERROR"
Sleep 5