Program to email a file nightly

Notice: Page may contain affiliate links for which we may earn a small commission through services like Amazon Affiliates or Skimlinks.

alex1002

Member
Apr 9, 2013
519
19
18
Good Day,
This may be akward to ask here, but I am trying to fnd a program that can take a file from a location and email it to someone nightly. Anyone ever seen this?
Thank you
 

seang86s

Member
Feb 19, 2013
164
16
18
For Windows, there is a command line utility called "blat" that can do what you want. Use the task scheduler to kick it off. Give it a google.
 

TuxDude

Well-Known Member
Sep 17, 2011
616
338
63
There are actually two parts to that question/problem. The first thing you need is a command-line e-mail client to send the message. Most linux distro's include 'sendmail' (or a compatible replacement from postfix or something), or you can use 'blat' on windows. Google if you need alternatives or other OSs. Next part is scheduling it nightly - cron on linux or task-scheduler on windows.
 

smithse79

Active Member
Sep 17, 2014
205
39
28
44
Windows doesn't actually need blat anymore. Powershell has the capability to send email from the command line using the send-mailMessage cmdlet. Either way, linux or Windows, this would be a very easy thing to script and set up as a cron job or scheduled task.
 

smithse79

Active Member
Sep 17, 2014
205
39
28
44
You can create a scheduled task to launch the below Powershell script.

To send an email with an attachment in Powershell:


Code:
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
$file = "C:\folder\file.csv"


$mailboxdata = (Get-MailboxStatistics | select DisplayName, TotalItemSize,TotalDeletedItemSize, ItemCount, LastLoggedOnUserAccount, LastLogonTime)

$mailboxdata | export-csv "$file"

$smtpServer = "127.0.0.1"

$att = new-object Net.Mail.Attachment($file)

$msg = new-object Net.Mail.MailMessage

$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$msg.From = "emailadmin@test.com"

$msg.To.Add("administrator1@test.com")

$msg.To.Add("administrator2@test.com")

$msg.Subject = "Notification from email server"

$msg.Body = "Attached is the email server mailbox report"

$msg.Attachments.Add($att)

$smtp.Send($msg)

$att.Dispose()
It's actually even easier than that. You no longer have to have it create a new-object and define all of it's parts. You could actually do it in one line but I like to make it easier to read/modify later.


Code:
    $smtpserver = 'mail.domain.com'
    $subject = 'here is your file'
    $body = 'This is the body of the emal'
    $from = 'computer@domain.com'
    $address = 'you@domain.com'
    $file = 'file.csv'
  
    Send-MailMessage -From $from -to $emailAddress -subject $subject -body $body -smtpserver $smtpserver -attachments $file