Office 365. Send email.

PowerShell script exchange

Office 365. Send email.

Veeam Logoby LGPC » Tue Aug 30, 2016 11:45 pm

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
LGPC
Influencer
 
Posts: 13
Liked: never
Joined: Fri Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC

Re: Office 365. Send email.

Veeam Logoby v.Eremin » Wed Aug 31, 2016 9:22 am

$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.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Office 365. Send email.

Veeam Logoby LGPC » Sat Sep 03, 2016 4:07 pm

I tried with 1 T and still no good.
LGPC
Influencer
 
Posts: 13
Liked: never
Joined: Fri Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC

Re: Office 365. Send email.

Veeam Logoby v.Eremin » Mon Sep 05, 2016 12:18 pm

Then, it might be worth reaching MS PowerShell community and checking with them why Office 365 cmdlets do not seem to work. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Office 365. Send email.

Veeam Logoby LGPC » Wed Sep 07, 2016 10:35 pm

Where?
LGPC
Influencer
 
Posts: 13
Liked: never
Joined: Fri Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC

Re: Office 365. Send email.

Veeam Logoby v.Eremin » Thu Sep 08, 2016 10:26 am

I'd start with Technet forums.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 3 guests