when i am trying to send email from Powershell using SMTP on a Windows Server 2012 R2 through our Exchange server in the same domain, i am getting following error:
Exception calling "Send" with "1" argument(s): "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated"
the code is:
# Define and create the message $strTo = "<to_address>" $strFrom = "<from_address>" $strSubject = "<subject of email>" $strBody = "<body of email>" $objMessage = New-Object System.Net.Mail.MailMessage –ArgumentList $strFrom, $strTo, $strSubject, $strBody # Define the SMTP server $strSMTPServer = "<mail.smtpserver.com>" $objSMTP = New-Object System.Net.Mail.SMTPClient –ArgumentList $strSMTPServer # Send the message $objSMTP.Send($objMessage)
I tried adding $objSMTP.UseDefaultCredentials = $true , but it didn't work either.
I am trying to send email from the logged-on domain account who is owner of the mailbox on Exchange 2013 server. I am able to send email from MS-Outlook using Exchange configuration from the same account.
Both the servers are on domain. Email I am trying to send to internal address. No external from/to address is involved.
I am able to send email when invoking credential arguments by adding following codes:
# Define Credential $Credentials = new-object System.Net.networkCredential # $cred = Get-Credential $Credentials.domain = "<domain name>" $Credentials.UserName = "<account name>" $Credentials.Password = "<account password>" $objSMTP.Credentials = $Credentials
Above code prompts ID/Password window where I need to type-in domain account and password, and hit enter. Then its working and email is sent. But i cannot use that, because the email send is part of scheduled task and has to be done without any user intervention
also I am able to send email from any other account who is owner of the mailbox.
Example:
the mailbox is owned by domain user mailbox_user1. User1, User2 are also owner of the same mailbox of mailbox_user1 in Exchange server 2013. When I am using User1 or User2 account to send email, the email is sent. but not from the original owner account mailbox_user1
Exchange Server 2013 Receive Connector properties:
Frontend Transport:
Client Frontend <server name> -> Security: only Exchange Users checkbox is marked
Default Frontend <server name> -> Security: Exchange servers, Legacy Exchange servers and Anonymous Users are selected
I guess Hubtransport properties has no effect on emails send/receive internally. Anonymous users is not selected under Hubtransport for valid reason.
I believe this is an Exchange server issue. Appreciate if anyone can help to resolve this. Thanks in advance