2
Send-MailMessage -SmtpServer "smtp.com.au" -From "[email protected]" -To "[email protected]" -Subject "Testing" -Attachments "\\Test\archive.zip" -Body "attached" 

I am using the above command to email a zip file but i don't see anything in the To ([email protected]) mailbox.

The command runs successfully without any errors.

3
  • Until someone provides an insight, you can try debugging the network request using Fiddler. Commented Aug 29, 2016 at 7:37
  • Any difference if you skip the zip-file? Commented Aug 29, 2016 at 8:04
  • @notjustme haven't tried without the zip file, thanks i will try this tomorrow when at work !! Commented Aug 29, 2016 at 9:23

2 Answers 2

1

I think the problem is in your function call. You miss a lot of parameters. Take a look on my working gmail example:

$password = ConvertTo-SecureString "123456789" -AsPlainText -Force $emailCredentials = New-Object pscredential ("[email protected]", $password) try { Send-MailMessage -From "[email protected]" -To "[email protected]" -Subject "subject" -Body "body" -SmtpServer "smtp.gmail.com" -Port 587 -Credential $emailCredentials -Encoding UTF8 -UseSsl -ErrorAction Stop } catch { echo $error[0] } 

There is no -Credential parameter in your call, and I'm almost sure, that's the problem. Also your smtp server may have this protocol on different port, this is what -Port is for. And finally -UseSsl, if smtp server is encrypting mails, then without this switch, your emails will be not send. -Encoding UTF8 is just for regional chars.

Check your $error[0], it may tell you, where the problem is. Check what is happening on your -From email. On gmail you can see sometimes auto-repiles, with error description.

I'm sorry for not giving you simple solution, but I don't have enough informations, to find it.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I tried this but i am getting the following error message.Send-MailMessage : Unable to connect to the remote server At line:4 char:5 + Send-MailMessage -From "[email protected]" -To "b@hot ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
1

Ok guys i have an update:

My command mentioned above is working absolutely fine. IT team has told me that we had issues with our SMTP the other day (When i had reported this issue) the emails eventually did come in (too late). I have tested the same this morning and it seems to be fine so a big thanks to all for your support.

I have got another question but i will post it separately.

1 Comment

I too have the same problem. Don't know what happened :( Unable to find the solution still :(

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.