- This topic has 3 replies, 2 voices, and was last updated 2 weeks, 6 days ago by
June 17, 2020 at 5:27 pm #236344ParticipantTopics: 1Replies: 1Points: 17Rank: Member
<p class=”_1qeIAgB0cPwnLhDF9XSiJM”>Hi, I am looking for a script to run through Powershell so I can receive an email notification when I receive an upload from Filezilla FTP server. I have Googled and this script below I found seemed to be the best one. I entered my gmail address and password in the SMTPCClient.Credentials where gmail_address and gmail_password are but it is still not working.</p>
<p class=”_1qeIAgB0cPwnLhDF9XSiJM”>I created a bat and ps1 file. Right-clicked in the whitespace in the bottom panel of filezilla > “Action after queue completion” > Run command for bat file and set execution policy unrestricted for Powershell. Am I missing something, or does someone have a better script? Thank you.</p>
$EmailFrom= "SENDER_EMAIL" $EmailTo= "RECIPIENT_EMAIL" $Subject= "EMAIL_SUBJECT" $Body= "EMAIL_BODY" $SMTPServer= "smtp.gmail.com" $SMTPClient= New-Object Net.Mail.SmtpClient($SmtpServer, 587) $SMTPClient.EnableSsl = $true $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("GMAIL_ADDRESS", "GMAIL_PASSWORD"); $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
June 17, 2020 at 10:17 pm #236380ParticipantTopics: 0Replies: 29Points: 273Rank: Contributor
Do you receive any error?
Does your gmail account use MFA?
If yes please refer to following article to create app password:
Also Gmail might not allow to send you email from your script as it might be considered unsecure app.
Please refer to following article:
Hope that helps.
June 18, 2020 at 11:43 am #236593ParticipantTopics: 1Replies: 1Points: 17Rank: Member
Thank you for the response and your assistance. The gmail account does not use MFA and I have already allowed gmail access for this app.
I ran the script in powershell and received this error:
Exception calling “Send” with “4” argument(s): “The specified string is not in the form required for an e-mail
At C:\fn\fn.ps1:12 char:1
+ $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException
+ FullyQualifiedErrorId : FormatException
What do I need to change in this line to make it work? Thanks.
June 18, 2020 at 11:05 pm #236710ParticipantTopics: 0Replies: 29Points: 273Rank: Contributor
From the error message it appears that one of the parameters ($from or $to) is not an email address.
Are you sending email to multiple recipients?
Please verify $from and $to email address.
Retype them manually if you copied them.
Hope that helps.
- You must be logged in to reply to this topic.