June 4, 2018 at 12:32 am
$File="gci \\abcd\efgh\ijkl | select -last 1"
$From = "adcb@gmail.com"
$To = "efgh@gmail.com"
$Attachment = $File
$Subject = "Here's the Email Subject"
$Body = "This is what I want to say"
$SMTPServer = "smtp.gmail.com"
Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -Attachments $Attachment
This is the error I receive:
Send-MailMessage : Illegal characters in path.
At line:1 char:1
+ Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Send-MailMessage], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.SendMailMessage
What am I doing wrong here?
Thanks
June 4, 2018 at 3:27 am
$File="gci \\abcd\efgh\ijkl | select -last 1"
$Attachment = $File
I assume that what you intended here was to get the last file on the folder in question - but instead you assigned a value of >gci \\abcd\efgh\ijkl | select -last 1< as the filename.
try
$File=gci \\abcd\efgh\ijkl | select -last 1
$Attachment = $File.Name
June 4, 2018 at 3:42 am
I tried that..it does not work.
It starts searching from the directory I am running the code from.
Send-MailMessage : Could not find file 'H:\files_06-04-2018_02-40-08.html'
My files exists in this folder \\abcd\efgh\ijkl.
Thanks
June 4, 2018 at 6:40 am
$File=gci \\abcd\efgh\ijkl | select -last 1
$Attachment = $File.FullName
you may need to enclose the filename with double quotes on the send mail step
June 4, 2018 at 7:44 am
It did not work
$File = "gci \\abcd\efgh\ijkl | select -last 1"
$From = "abcd@gmail.com"
$To = "efgh@gmail.com"
$Attachment = $File
$Subject = "Here's the Email Subject"
$Body = "This is what I want to say"
$SMTPServer = "smtp.gmail.com"
Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -Attachments "$Attachment" –DeliveryNotificationOption OnSuccess
Send-MailMessage : Illegal characters in path.
At line:1 char:1
+ Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Send-MailMessage], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.SendMailMessage
June 4, 2018 at 8:21 am
offcourse not - instead of using my code you reverted back to your original one
June 4, 2018 at 10:31 pm
I tried that already.Did not work
PS H:\> $File = gci \\abcd\efgh\ijkl | select -last 1
PS H:\> $From = "abcd@gmail.com"
PS H:\> $To = "defg@gmail.com"
PS H:\> $Attachment = $File.FullName
PS H:\> $Subject = "Here's the Email Subject"
PS H:\> $Body = "This is what I want to say"
PS H:\> $SMTPServer = "smtp.gmail.com"
PS H:\> Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -Attachments "$Attach
ment" –DeliveryNotificationOption OnSuccess
Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server
response was: 5.7.0 Must issue a STARTTLS command first. e10-v6sm92576318pfb.136 - gsmtp
At line:1 char:1
+ Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpExcept
ion
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
June 5, 2018 at 12:14 am
yeah.. with a totally different error
Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server
response was: 5.7.0 Must issue a STARTTLS command first. e10-v6sm92576318pfb.136 - gsmtp
so my change did indeed work - now you have another issue that you will need to chase after
June 5, 2018 at 7:47 am
I get an email when I execute the same code without any attachments.
I don't think the error has anything to do with smtp.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy