-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Enable Send-MailMessage on CoreCLR #3869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@jeffbi You need add new record in test/powershell/engine/DefaultCommands.Tests.ps1 |
|
@iSazonov Thanks, I wasn't aware of this. I see that there already is a record for Send-MailMessage. Do I just need to add |
|
Yes, you need edit and add -or $CoreWindows -or $CoreUnix |
|
Done. |
|
@jeffbi The tests is skipped on both CI - I believe we should remove its at all. Maybe we can merge without tests if the cmdlet passes manual tests locally. Related https://github.com/tedious/DovecotTesting/blob/master/resources/Scripts/Provision.sh#L28 |
|
@iSazonov I would guess that the test is being marked as Pending due to the machine name not matching the one specified in the test script. The test does require some pretty specific configuration. I have been able to manually send mail to myself on Linux with the cmdlet. I don't have an SMTP server for my Windows box to test with. @JamesWTruher, @SteveL-MSFT, do you have thoughts on this? |
|
@iSazonov So you know, when the CI checks failed, the error was pointing to |
|
I did not saw problem with test/powershell/engine/Remoting/SSHRemotingAPI.Tests.ps1 - I saw only failed DefaultCommands.Tests.ps1 that is expected. I believe it is very expensive install a mail server on CI VMs. |
|
|
||
| It @PesterArgs { | ||
| $body = "Greetings from me." | ||
| $subject = "Test message" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't you also validate the subject?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
| } | ||
|
|
||
| $user = "jeff" | ||
| $inPassword = Select-String "^${user}:" /etc/passwd -ErrorAction SilentlyContinue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like user 'jeff' will almost always not exist so this test is always pending?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to current user
| return | ||
| } | ||
|
|
||
| $domain = "Chinstrap" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to above, this will almost always fail and thus be Pending, seems like if mail is installed you should be able to rely on root@computername?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What it actually should be is current_user$computername. While the test takes steps to avoid deleting an existing mailbox, it still made me nervous, so I left those hard-coded names in, partially to call attention to the situation.
To use root@computername, the test would need to be running as root in order to access root's mailbox. Is that what the CI environment is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current user is probably correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to current user on current machine
| $PesterArgs["Name"] += " (pending: mailbox not empty)" | ||
| return | ||
| } | ||
| $alreadyHasMail = $false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this, you set $alreadyHasMail to $true above and then it's always set to $false here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one of those steps to avoid deleting an existing mailbox. In the AfterAll block, the $alreadyHasMail variable is checked before deleting the mailbox. The early return at line 104 keeps that set to $true if the mailbox is not empty.
| $PesterArgs = @{ Name = "Can send mail message from user to self"} | ||
| $alreadyHasMail = $true | ||
|
|
||
| if (-not $IsLinux) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to check if a smtp server is installed or is that always the case on Linux/Mac?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Linux, an SMTP server is not installed by default, since there are at least two to choose from, perhaps more.
I'll have to look into how to detect from PowerShell if anyone's listening on port 25.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
JamesWTruher
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the important check to be added is to be sure that an SMTP server is installed and running on the system
| return | ||
| } | ||
|
|
||
| $user = "jeff" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this testuser please. I'm using this account name in another upcoming PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is testuser the username the CI tests will run as?
The permission bits on a user's mailbox are rw------- so a test might be able to send mail to another user, but it won't be able to read the mailbox to verify that the mail was sent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use an environment variables:
- AppVeyor - APPVEYOR_ACCOUNT_NAME
- Travis - USER
| return | ||
| } | ||
| $alreadyHasMail = $false | ||
| Set-Content -Value "" -Path $mailBox -Force -ErrorAction SilentlyContinue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do permissions need to be set on this mailbox? I seem to remember that the permissions for mailbox files are special
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They don't seem to be special, just rw-------
| It @PesterArgs { | ||
| $body = "Greetings from me." | ||
| $subject = "Test message" | ||
| Send-MailMessage -To $address -From $address -Subject $subject -Body $body -SmtpServer 127.0.0.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one more check needed above to be sure that there's an smtp server running on localhost
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
| AfterAll { | ||
| if (-not $alreadyHasMail) | ||
| { | ||
| Set-Content -Value "" -Path $mailBox -Force -ErrorAction SilentlyContinue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this just be delete the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless we're running as root or as a member of the mail group, we can write to the file but we cannot delete it.
* Add check for SMTP server * Send mail to/from currently logged-in user on currently-named machine * Do not try to clear/create the mailbox before the test * Add validation of Subject
|
Can we use .Net Fake SMTP Server ? |
| @@ -0,0 +1,147 @@ | |||
| Describe "Basic Send-MailMessage tests" -Tags CI { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this test require Administrator on Windows or root on all non-Windows platforms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently this test runs only on Linux. So long as the sender/receiver of the email is the currently logged-in user, running as root is not required.
I've been looking into ways to make tests more cross-platform, using a suggestion from @iSazonov, but it's going to take some effort.
My personal feeling is that I'd like to create a separate issue for testing Send-MailMessage and have this PR be taken as-is, but I don't know if that works with testing policies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeffbi create a separate issue for that and link it to this
|
@SteveL-MSFT @JamesWTruher Have all of you concerns been addressed? Do you have any additional comments? |
|
@JamesWTruher Do you have any additional comments? |
|
LGTM |
Contributes to the completion of #2123 and #2240.
Now that the requisite components are implemented in corefx, compilation of the Send-MailMessage cmdlet has been enabled.
This PR includes a test script that allows the cmdlet to be tested against a working local SMTP server, but only on Linux and under specific conditions. A separate issue will be opened for improving test coverage and including additional platforms.