PowerShell script exchange
Post Reply
LGPC
Influencer
Posts: 13
Liked: never
Joined: Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC
Contact:

Office 365. Send email.

Post by LGPC »

I tried just the email following this article:

Code: Select all

# Email SMTP server
$SMTPServer = 'smtp.office365.com'

$SmtpUser = 'jbadre@southhackensacknj.org'

$smtpPassword = ''P@ssw0rd1'

# Email TO
$MailTo = 'jeff@letsgetpersonalcomputing.com'

# Email FROM
$MailFrom = 'jbadre@southhackensacknj.org'

# Email subject
$MailSubject = "Test using $SmtpServer"
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $SmtpUser, $($smtpPassword | ConvertTo-SecureString -AsPlainText -Force)
Send-MailMessage -To "$MailtTo" -from "$MailFrom" -Subject $MailSubject -SmtpServer $SmtpServer -UseSsl -Credential $Credentials
And got this error:

Code: Select all

PS C:\> C:\EmailTest.ps1
Send-MailMessage : Cannot validate argument on parameter 'To'. The argument is null or empty. Provide an argument that is not null 
or empty, and then try the command again.
At C:\EmailTest.ps1:26 char:22
+ Send-MailMessage -To "$MailtTo" -from "$MailFrom" -Subject $MailSubject -SmtpSer ...
+                      ~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SendMailMessage
veremin
Product Manager
Posts: 20397
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Office 365. Send email.

Post by veremin »

$MailTo = 'jeff@letsgetpersonalcomputing.com'
Send-MailMessage -To "$MailtTo"
There is a typo in your script. You've declared variable as $MailTo (with one t), but, then, you try to access it as $MailtTo (with double T), thus, the issue. Thanks.
LGPC
Influencer
Posts: 13
Liked: never
Joined: Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC
Contact:

Re: Office 365. Send email.

Post by LGPC »

I tried with 1 T and still no good.
veremin
Product Manager
Posts: 20397
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Office 365. Send email.

Post by veremin »

Then, it might be worth reaching MS PowerShell community and checking with them why Office 365 cmdlets do not seem to work. Thanks.
LGPC
Influencer
Posts: 13
Liked: never
Joined: Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC
Contact:

Re: Office 365. Send email.

Post by LGPC »

Where?
veremin
Product Manager
Posts: 20397
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Office 365. Send email.

Post by veremin »

I'd start with Technet forums.
Post Reply

Who is online

Users browsing this forum: R.Timmons and 12 guests