MS Exchange Server SMTP name for PowerShell script - powershell

If I wamted to send an email from a recently migrated MS Outlook account on MS Exchange Server to a MS Hotmail account on IMAP using PowerShell 5 like this:
$splatr = #{
To = 'her#hotmail.com'
From = 'him#outlook.com'
Subject ='test'
Body ='test'
SmtpServer ='??????'
Port = 587
UseSSL = $true
}
Send-MailMessage #splatr -Credential him#outlook.com
where would I get the Outlook/Exchange Server SMTP name from, please?
If it were the other way around, I would use
SmtpServer ='smtp-mail.outlook.com'
Thank you.

From Outlook,
Start Microsoft Outlook.
Click the "File" tab on the ribbon and then click "Info."
Click the "Account Settings" button and then select "Account Settings."
Select the account for which you want to look up the SMTP information and then click the "Change" button.
Look in the field next to "Outgoing Mail Server (SMTP)" to determine what SMTP server your email account is using.
Click the "Cancel" button to return to the main Outlook window.
Alternative;
Type "nslookup". Your computer's DNS Server name and IP address will
be displayed.
Type "set type=mx" - This will cause NSLOOKUP to only return what are
known as MX (Mail eXchange) records from the DNS servers. For an
example, type "hotmail.com" or use your own domain name.

Related

Powershell and Exchange - Set SMTP Primary address

I'm in an hybrid environement with Exchange 2016 and Office 365.
I wish to script the process to enable a Remote Mailbox, an change the primary SMTP address of a user.
By example, I have a user who Remote Mailbox has been enabled. He has a SMTP primary address like this: User1#My-Group.com
With the command below, I can change the SMTP primary address just fine:
#Disable Email Address Policy
Set-RemoteMailbox User1 -EmailAddressPolicyEnabled $false
#Change SMTP address
Set-RemoteMailbox User1 -PrimarySmtpAddress "User1#My-good-address.com"
Everything is just fine, when I go to my On Premise Exchange 2016, I can see my user1 addresses like that:
SMTP:User1#My-good-address.com
smtp:User1#My-Group.com
...
But, when I put back Email Address Policy to $True, I have this result on Exchange:
SMTP:User1#My-Group.com
smtp:User1#My-good-address.com
...
That doesn't happen when I do the change manually.
Does anyone know why I have this behavior?
Thanks in advance !
Problem solved...
I was just on the ONLY USER who was missing an attribute, and the wrong email policy was applied.

Powershell Script for sending emails doesn't work, but no errors

i've been trying to build a small powershell script, to inform employees via email if their windows OS is not up to date, i was planning to use our own email relay to send those emails, so i wanted to use this script to test sending out the email
Send-MailMessage -SmtpServer '<ip of email relay>' -To '<employee email>' -From '<central email>' -Subject 'test' -Body 'this is a test' -Port 25
now when i run this script powershell says the script has been executed, no errors, but the email is never sent/received.
Is there anything i'm missing here ?
edit: we are running hmailserver as our local smtp server
The first step to review is.
If the central email user have enough permissions to relay email.
Then you could review if the pc or laptop where the script is executed is in the list of connections allowed to relay through the SMTP.
To Review this setting you need check the Route configuration in your email server.In this link you will find the settings related on how and where emails for specific domains should be delivery
And you should review your client firewall make sure your firewall is not blocking port 25 or 587.

Cannot send forwarding mail

I have an xmail server "mailserver.idv"
however , when I buy domain name from Google Domains , there is a Email Forwarding Service.
Now I have 2 kinds of mail address:
user#mailserver.idv is a really account on my "mailserver.idv" mail server
test#mailserver.idv is a forwarding mail to my g-mail "test#gmail.com"
I can send mail from user#mailserver.idv to test#gmail.com directly
But I cant send user#mailserver.idv to test#mailserver.idv
I noticed that in smail logs, it's diff. between SMTP & LOCAL
How can I set config file to send all mail as out "SMTP" always?
I solved this by add mailproc.tab under /domains/mailserver.idv/test/
"redirect"[tab]"test#gmail.com"[newline]

IIS 7 - Can't send email until Print Spooler service restarted

WEB ENVIRONMENT
IIS 7.5, Windows 2008 R2, Classic ASP
So every couple of days or weeks (its totally random) one of our webservers will stop sending emails and report an error code of "80040211", which is a generic "Could not send email" message. I'm using a "CDO.Message" object to do handle sending mail, and mail is being sent on a separate, in house SMTP server. Once the error occurs, I restart the "print spooler" service on that server, it can send mail immediately.
This happens on our Production and Development servers. All servers are running IIS 7.5, Windows 2008 R2, and we use Classic ASP.
Does anyone have an idea of why the Printer Spooler service would stop email from being sent? and once its restarted, email works again?
Update: here's the code I'm using in case anyone wants it for reference:
SET mail = Server.CreateObject("CDO.Message")
mail.To = "myWorkEmail#myjob.com"
mail.From = "myWorkEmail#myjob.com"
mail.Subject = "Test subject"
mail.HTMLBody = "Test email"
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp" 'this is the name of the SMTP server, its name is literally "smtp"
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
mail.Configuration.Fields.Update
ON ERROR RESUME NEXT
mail.Send
ON ERROR GOTO 0
SET mail = NOTHING

Send email SMTP from localhost with WAMP setup

I'm trying to configure my php.ini file so I can send emails from 'localhost' in my dev environment using PHP. I no longer have access to an open SMTP server, and Gmail no longer works with their new SSL setup. I've done a lot of research and seen lots of "solutions" here and elsewhere, but they don't work. I've tried installing local SMTP servers (hMailServer asks for a password to install, Free SMTP Server doesn't work, etc).
Does anyone know of a free SMTP server I can setup in my php.ini file, or any other way to send mail from localhost (I just need it for testing purposes). I don't want to have to change code and send emails in a completely different way when I switch to production. (I'm using Zend and the Zend_Mail class)
You could try using Zend_Mail_Transport_File for testing instead.
$mail = new Zend_Mail();
$mail->send(new Zend_Mail_Transport_File());
In windows I was usually using Mercury to sent emails from localhost for testing purposes. Mercury is free for non-commercial use and it is also used in xampp.
Solution for XAMP, WAMP or etc..
download hMailServer; Then configure program:
When you first open hMailServer Administrator, you should add new domain.
Click on the "Add Domain ..." button at the Welcome page.
Under the domain text field, enter your computer's IP, in this case it should be 127.0.0.1.
Click on the Save button.
Go to Settings>Protocols>SMTP and select "Delivery of Email" tab
Enter "localhost" in the localhost name field.
Click on the Save button.
If you need to send mail using a FROM addressee of another computer, you need to allow deliveries from External to External accounts. To do that, follow these steps:
Go to Settings>Advanced>IP Ranges and double click on "My Computer" which should have IP address of 127.0.0.1
Check the Allow Deliveries from External to External accounts checkbox.
Save settings using Save button.
If you use Gmail account, then need small modification :
Go to Settings>Protocols>SMTP and select "Delivery of Email" tab
Enter "smtp.gmail.com" in the Remote Host name field.
Enter "465" as the port number
Check "Server requires authentication"
Enter your Google Mail address in the Username field
Enter your Google Mail password in the password field.
Check "Use SSL"
You will have to use this confuguration for the transport of the mail
$transport = new Mail\Transport\Smtp();
$options = new Mail\Transport\SmtpOptions (array(
'name' => 'host',
'host' => 'smtp.gmail.com',
'port'=> 587,
'connection_class' => 'login',
'connection_config' => array(
'username' => "yourGmailUserMail",
'password' => 'yourGmailPassword',
'ssl'=> 'tls',
),
));
$transport->setOptions($options)
;
and it will works.