Reputation: 37
The following command successfully sends an e-mail using the parameters specified in the command:-
Send-MailMessage -From "<[email protected]>" -To "<[email protected]>" -Subject "Sending the Attachment" -Body "Forgot to send the attachment. Sending now." -SmtpServer "fqdn.smtprelay.com"
As soon as I add any kind of attachment, regardless of size, file extension (.txt, .zip etc.) the command apparently completes without generating any kind of error into the console output but the e-mail never hits the SMTP relay when I track the mail, it's almost as if the command fails but according to PowerShell it hasn't, it executes the command without any kind of output.
This is the command I'm using:
Send-MailMessage -From "<[email protected]>" -To "<[email protected]>" -Subject "Sending the Attachment" -Body "Forgot to send the attachment. Sending now." -SmtpServer "fqdn.smtprelay.com" -Attachments "C:\Temp\targetfile.zip"
Does any body have any advice on how I can go about troubleshooting further? It seems to be such a simple issue but I feel that I have now exhausted all options. I have verified that the target file exists and can be accessed from the PowerShell console.
Also, I can successfully establish a telnet connection to the SMTP relay on port 25 without authentication and generate a basic e-mail, the problem seems to be when I add an attachment.
Upvotes: 1
Views: 913
Reputation: 37
New hosted e-mail security system was rejecting mail based on security policies, because the attachment was an unzipped HTML file attached to the e-mail it was being rejected as a potential security threat.
Added new code to firstly compress file before attaching to e-mail and sending - now works perfectly.
Upvotes: 1