ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Trigger the Send function in a new email from command line

<< < (2/2)

4wd:

--- Code: PowerShell ---param (  [string]$toaddr = $(throw "EmailArc.ps1 <email address> <file|folder>"),  [string]$file = $(throw "EmailArc.ps1 <email address> <file|folder>")) $arcfile = $env:temp + '\' + ([System.IO.Path]::GetFileNameWithoutExtension($file)) + '.zip' if (Test-Path $arcfile) {#  Write-Host 'Updating archive'  Compress-Archive -Path $file -Update -DestinationPath $arcfile -CompressionLevel Optimal | Out-Null} else {#  Write-Host 'Creating archive'  Compress-Archive -Path $file -DestinationPath $arcfile -CompressionLevel Optimal | Out-Null} $newarc = $arcfile -replace '(.*)(\.zip$)', '$1zip'Move-Item -Path $arcfile -Destination $newarc $ol = New-Object -comObject Outlook.Application $mail = $ol.CreateItem(0) $Mail.Recipients.Add($toaddr) $Mail.Subject = (Split-Path $file -Leaf)$Mail.Body = "Archive containing: " + (Split-Path $file -Leaf) + "`n`nRename *zip to *.zip"$Mail.Attachments.Add($newarc)$Mail.Send()  Start-Sleep -Seconds 1 Remove-Item $newarc

Shades:
While blat offers their command-line mailer for free (non-commercial use only), I found it to behave problematic in an automatized process, where I generate a custom mail message with attachment. Then I found CMail (commercial use allowed) and that worked much more reliable in my scenario. Perhaps this is of some use to you too.

x16wda:
Thanks for the link Shades - I haven't needed anything other than what Blat offers yet, but I'll need to play with CMail now since it has TLS support. Always good to have more tools in the toolbox!

Navigation

[0] Message Index

[*] Previous page

Go to full version