Can't use send-mailmessage when using PSFTP Module

Pagina: 1
Acties:
  • 313 views

Onderwerpen

Vraag


Acties:
  • 0 Henk 'm!

  • erikjenniskens
  • Registratie: September 2014
  • Laatst online: 08-08 09:15
I've made a Powershell script which uploads data to a NAS. After the Upload is completed the script should send an Email message.

When the script tries to send a mailmessage I get an error saying I used an incorrect security certificate.

This error only shows up when I use the PSFTP module. When i run the sendmail code on its own it works just fine.

The FTP session itself isn't alive anymore so this shouldn't be a problem.

Can someone point me in the right direction to sort this problem out?I've made a Powershell script which uploads data to a NAS. After the Upload is completed the script should send an Email message.

When the script tries to send a mailmessage I get an error saying I used an incorrect security certificate.

This error only shows up when I use the PSFTP module. When i run the sendmail code on its own it works just fine.

The FTP session itself isn't alive anymore so this shouldn't be a problem.

Can someone point me in the right direction to sort this problem out?


$Execution = Get-ExecutionPolicy

If($Execution -eq "RemoteSigned")
{
Write-Host "HOI" -BackgroundColor Black -ForegroundColor Green
}
Else
{
Set-ExecutionPolicy Remotesigned
}
1.Module PSFTP importing
Import-Module PSFTP

$secpasswd = ConvertTo-SecureString “Wachtwoord” -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential (“Admin”, $secpasswd)

Variables

$Session = "Alive"
$ftp = "IP"
$Credentials = "Admin"
$FtpFile = "C:\Test\Back-up.ps1"
$ftpDestination = "FTPLOCATIE"

2.Connect to FTP with module PSFTP

Set-FTPConnection -Server $ftp -Credentials $mycreds -Session $Session
( Connect to ftp)
3.TPItem for uploading to NAS

Get-ChildItem $FtpFile | Add-FTPItem -Session $Session -Path $ftpDestination -Overwrite

4.Section for mailing,variables

$secpasswd = ConvertTo-SecureString “Wachtwoord” -AsPlainText -Force
$mycredsMail = New-Object System.Management.Automation.PSCredential (“Email-address”, $secpasswd)

5. Section for mailing

$Smtp = "smtp.office365.com"
$Port = "587"
$To = "Email"
$Subject = "Back-up"
$From = "Email

6. this is where i want send the mail i use ssl

Send-MailMessage -to $To -from $From -Subject $Subject -SmtpServer $Smtp -Credential $mycredsMail -Port $Port -UseSsl

Alle reacties


Acties:
  • 0 Henk 'm!

  • RobIII
  • Registratie: December 2001
  • Niet online

RobIII

Admin Devschuur®

^ Romeinse Ⅲ ja!

(overleden)
We speak Dutch here en we zien graag dat je code tags gebruikt als je code post ;)
Open gerust een nieuw topic, maar doe dat dan in 't Nederlands a.u.b. en hanteer daarbij even onze Quickstart.

There are only two hard problems in distributed systems: 2. Exactly-once delivery 1. Guaranteed order of messages 2. Exactly-once delivery.

Je eigen tweaker.me redirect

Over mij


Dit topic is gesloten.