0

I installed cygwin together with this package: https://cygwin.com/packages/x86_64/email/email-3.2.1-git-1

Do you know how to create a bat file and send email with attachment using cygwin email package in windows 10?

Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • Why not just use the built-in [`powershell`](https://stackoverflow.com/questions/58373405/how-to-send-email-to-distribution-list-in-outlook-using-task-scheduler)? – Gerhard Apr 20 '22 at 08:53
  • ohh okay okay I didn't know about this. Ill check this one, thank you – Iskooolar2 iskoolar2 Apr 20 '22 at 08:58
  • I have sent an email using powershell, however can I do this using a batch file? So that a user is only one click away? @Gerhard – Iskooolar2 iskoolar2 Apr 20 '22 at 09:47
  • either wrap the `powershell` command in `batch-file` or simply save the content of the powershell script as `send_email.ps1` then in the batch file do `powershell .\send_email.ps1` obviously either specify full path to the `ps1` file or put it in the same directory as the `batch-file` – Gerhard Apr 20 '22 at 09:59

1 Answers1

0

Powershell is builtin to your windows device,powershell 2.0 and up has the Send-MailMessage function. If you really need to use batch-file for this task, you can simply call powershell from within a batch-file:

@echo off
powershell Send-MailMessage -From 'someone@someserver.net' -To 'recipient@address.com' -Subject 'Test email' -Body 'This is a test' -SmtpServer mailserver.domain.com -Attachments 'C:\Some Dir\Somefile.txt'

to break it down into a readable form on Stackoverlow:

powershell Send-MailMessage 
      -From 'someone@someserver.net'
      -To 'recipient@address.com'
      -Subject 'Test email'
      -Body 'This is a test'
      -SmtpServer mailserver.domain.com
      -Attachments 'C:\Some Dir\Somefile.txt'
Gerhard
  • 22,678
  • 7
  • 27
  • 43