mirror of
https://gitlab.com/harald.mueller/aktuelle.kurse.git
synced 2024-11-30 21:51:56 +01:00
35 lines
1.4 KiB
PowerShell
35 lines
1.4 KiB
PowerShell
|
|
# Method to write an email with the logfile as attachement
|
|
#--------------------------------------------------------------------------------------------------
|
|
function sendmail() {
|
|
$toMail = "harald.mueller@bluewin.ch"
|
|
$attachment = "C:\Users\Harald\OneDrive\Technik\mails\data.pdf"
|
|
|
|
$SMTPServer = "smtp.gmail.com"
|
|
$SMTPPort = "587"
|
|
$Username = "invoice.autointerleasing@gmail.com"
|
|
|
|
# password of the mail account
|
|
$Password = "invoice77autointerleasing" | ConvertTo-SecureString -AsPlainText -Force
|
|
|
|
$subject = "Powi mail"
|
|
$body = "Logfile has been modified. Please review attached document $entry."
|
|
|
|
$message = New-Object System.Net.Mail.MailMessage
|
|
$message.subject = $subject
|
|
$message.body = $body
|
|
$message.to.add($toMail)
|
|
$message.from = $username
|
|
$message.attachments.add($attachment)
|
|
|
|
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
|
|
$smtp.EnableSSL = $true
|
|
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
|
|
$smtp.send($message)
|
|
}
|
|
## (Get-Credential).password | ConvertFrom-SecureString > mailpasswort.txt
|
|
## $pw = Get-Content .\mailpasswort.txt | ConvertTo-SecureString
|
|
## $cred = New-Object System.Management.Automation.PSCredential "MailUser", $pw
|
|
## Send-MailMessage -Credential $cred -to "harald.mueller@bluewin.ch" -from "PowerShell <ps@fabrikam.de>" -Subject "Test" -body "Test für Send-MailMessage"
|
|
|
|
sendmail |