Skip to content
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

Support for CoreCLR #212

Closed
niemyjski opened this issue Jul 7, 2015 · 100 comments
Closed

Support for CoreCLR #212

niemyjski opened this issue Jul 7, 2015 · 100 comments
Labels
enhancement New feature or request

Comments

@niemyjski
Copy link

Will there be any support for the new core clr?
https://aspnet.uservoice.com/forums/252111-asp-net-vnext/suggestions/7648077-corefx-should-include-system-net-mail

Also, it would be sweet if we could configure this library with smtp defaults via environmental variables as this is a part of vnext.

@jstedfast
Copy link
Owner

I'll happily accept a csproj file to build for Core CLR but I don't want to add support for loading default settings from environment variables - it just would not fit nicely with the API.

@jstedfast
Copy link
Owner

if you could send me an empty Library Project .csproj file for CoreCLR, I can probably commit them in a few minutes (I'm betting it compiles without any (or very few) changes).

Note: I'd do this myself if I was 1. using Windows and 2. had VS 2015 installed, but I'm on a Mac.

@jstedfast
Copy link
Owner

Actually, can't you just reference a .NET4.5 assembly and be done?

@niemyjski
Copy link
Author

There are two different run times, the core clr can't reference .net 4.5/4.6 assemblies

@niemyjski
Copy link
Author

Vnext won't support web.config/ will have generic configuration that runs off anything (environment variables, json, ini, etc)

@jstedfast
Copy link
Owner

Okay, well, if you can get me a blank Library Project template, I can probably copy/paste the <Compile Include="..." /> lines into it and it'll probably more-or-less work. Looks like serialization isn't supported, so I'll probably have to add a DEFINE for that, but no big deal.

@jstedfast
Copy link
Owner

Do you mean you want a DNX project?

@niemyjski
Copy link
Author

Yes, DNX which uses a new project format too.

@jstedfast jstedfast added the invalid This doesn't seem right label Jul 25, 2015
@jstedfast
Copy link
Owner

You can already reference MimeKit and MailKit from DNX projects in VS2015 (I just tested this).

@akoeplinger
Copy link

@jstedfast it only works for the Desktop .NET target, but not for the .NET Core based one, which is what this issue was about:

image

@jstedfast
Copy link
Owner

Ah, thanks. What's the correct way to create a .NET Core project in VS2015? The NewProject templates I see don't make it obvious (to me, at least).

@akoeplinger
Copy link

@jstedfast If you create a new "Visual C# > Web > Class Library (Package)" project, that should give you the refactored BCL packages in project.json with the new dotnet TFM (read more about that here).

That uses the DNX project system though, I believe there'll be a way to make a csproj targeting .NET Core in the future.

@jstedfast
Copy link
Owner

Thanks, I'll give that a go

@jstedfast
Copy link
Owner

Hmmm, having trouble getting this to work because it wants to slurp up every file in the directory whether I want to include it or not.

The only solution I can think of is using symlinks...

@akoeplinger
Copy link

@jstedfast you can include/exclude patterns of files in compile or just list each file separately in compileFiles: https://github.com/aspnet/Home/wiki/Project.json-file#sources

@jstedfast
Copy link
Owner

oooooohhhhh, thanks. I'll give that a try.

@jstedfast
Copy link
Owner

Okay, so I've almost got MimeKit ported, but I've got the following build errors that I have no idea what they mean or how to solve them:

screenshot

@akoeplinger
Copy link

@jstedfast that looks like the incompatibility with the Xamarin Tools: https://github.com/dotnet/corefx/issues/449. Uninstall them and it should work (builds fine here).

@jstedfast
Copy link
Owner

Ah, hmmm, how am I going to create a nuget with all these? if I have to uninstall the Xamarin stuff? :(

@akoeplinger
Copy link

I think that's just a point in time thing until the incompatibility is fixed? btw. you can turn on producing a .nupkg from "Properties > Build > Produce outputs on build".

@akoeplinger
Copy link

@jstedfast Here's an interesting blogpost about how to target .NET Core without DNX: http://oren.codes/2015/07/29/targeting-net-core/

@joeaudette
Copy link

I just came across this while researching how to send mail in dnxcore50. It seems that getting mailkit/mimekit to work would be the best hope since there is no system.net.mail in the current corefx and it won't be there at the 1.0 release and no timeline has been given for when they will port that.

It seems like very important functionality for any web app to send email so I'm kind of surprised MS hasn't given it higher priority. MailKit/MimeKit looks far superior to system.net.mail anyway. I guess the only 3rd option is to use REST apis from 3rd party email services, but I think it will be a big disappointment to many people trying to port their web apps to dnxcore50 when they find there is nothing available to easily send email.

I would be glad to help in any way that I can to assist in getting these projects ported. Looking at the code I don't feel like I'm qualified to solve it or send a pull request. But I do know about the new project system and how to resolve errors like the ones in the screenshot you posted so maybe I could help a little.

There is a new .xproj file and a project.json file that are the main new things.

The project.json file has all the nuget dependencies, framework targets and dependencies and meta data about the project. VS 2015 will automatically restore the dependencies if you edit project.json to add dependencies. you can also use

dnu restore 

from the command line in the project directory to restore nuget dependencies.

The build output in the new system is a nuget package per project. VS 2015 will create the nuget package for you based on the project.json file. I'm sure there is also a command line way to do it and vs is just automating that stuff.

Those errors you had in the screenshot look likely related to some problem in the project.json file.

If there is anything I could do to assist you in any way please let me know. If there was a kickstarter to raise money to make it worthwhile for you to work on this as a priority to get it done I would be willing to make a small donation and I'm sure others would too.

@jstedfast
Copy link
Owner

I actually plan to look into this again soon. Hoping the incompat between Xamarin and DNX is gone now.

@jstedfast jstedfast reopened this Dec 1, 2015
@joeaudette
Copy link

That is great news! If you run into unexpected errors please post them and maybe I can help.

@jstedfast jstedfast added enhancement New feature or request and removed invalid This doesn't seem right labels Dec 3, 2015
@jstedfast
Copy link
Owner

If you can figure out why this is failing, that'd be helpful:

https://ci.appveyor.com/project/jstedfast/mimekit/build/1.2.16.191

Also, how do I restore nuget packages in VS2015?

@jstedfast
Copy link
Owner

I just got a report last night that SslStream.AuthenticateAsClient() is missing in nightly builds of RC2, so I might need to use some other solution for SSL/TLS. Hopefully that's just a bug, though.

@joeaudette
Copy link

I'm still on RC1 here. Seems like the error would be missingmethodexception if that were the problem.
Based on some googling of the error I tried adding a ServerCertificateValidationCallback that returns true but the error did not change, my code is like this:

public async Task SendEmailAsync(
        SmtpOptions smtpOptions,
        string to,
        string from,
        string subject,
        string message)
    {
        var m = new MimeMessage();

        m.From.Add(new MailboxAddress("", from));
        m.To.Add(new MailboxAddress("", to));
        m.Subject = subject;
        m.Body = new TextPart("plain") { Text = message };

        using (var client = new SmtpClient())
        {
            client.ServerCertificateValidationCallback = delegate (
                Object obj, X509Certificate certificate, X509Chain chain,
                SslPolicyErrors errors)
            {
                return (true);
            };

            await client.ConnectAsync(smtpOptions.Server, smtpOptions.Port, smtpOptions.UseSsl);

            // Note: since we don't have an OAuth2 token, disable
            // the XOAUTH2 authentication mechanism.
            client.AuthenticationMechanisms.Remove("XOAUTH2");

            // Note: only needed if the SMTP server requires authentication
            if(smtpOptions.RequiresAuthentication)
            {
                client.Authenticate(smtpOptions.User, smtpOptions.Password);
            }


            client.Send(m);
            client.Disconnect(true);
        }

    }

@akoeplinger
Copy link

@jstedfast the sync versions were removed (dotnet/corefx#4868), only the async versions like AuthenticateAsClientAsync remain.

@jstedfast
Copy link
Owner

@joeaudette Sorry, I didn't meant to say that the reason for the failure in your case was a missing method, just that there seems to be development going on around AuthenticateAsClient and thus the disappearance of that method from RC2 might be related.

@akoeplinger ah, thanks.

@joeaudette
Copy link

so, what should I do at this point, just wait for coreclr RC2 to be released and try again?

@jstedfast
Copy link
Owner

So one place where that error can be thrown from what I can tell is if you connect to a plain-text port and then try to send an SSL handshake (which is what AuthenticateAsClient does).

Is it possible that you are connecting to a non-SSL port?

@joeaudette
Copy link

I'm testing against elastic email smtp relay using port 2525 which they say is a TLS port, but it looks like there are a few supported ports so I could try one of the others, though in my account settings there they indicate 2525 specifically. It appears they have alternate non ssl settings I can try on port 25. I'll report back after trying a few things.

@jstedfast
Copy link
Owner

Sometimes when someone claims a port is a "TLS" port, what they mean is that the client should send a STARTTLS request to toggle into TLS mode, but until then, it is a plain-text port.

I don't know if that's the case here or not.

@joeaudette
Copy link

is there a way I can try that?

@jstedfast
Copy link
Owner

yea, just change your client.ConnectAsync(...) logic to client.ConnectAsync(smtpOptions.Server, smtpOptions.Port, SecureSocketOptions.StartTLS)

@joeaudette
Copy link

I got the same error trying with SecureSocketOptions.StartTLS

It did work when I changed to use the non ssl settings though that is not ideal. I will experiment with the other ssl ports they provide.

@jstedfast
Copy link
Owner

Okay, so it sounds like 2525 might really be an SSL-wrapped port (e.g. you need SSL/TLS immediately when you connect after all).

Sadly I'm not sure how to work around this issue unless I can just make the code use AuthenticateAsClientAsync() and it'll magically work.

@joeaudette
Copy link

Good news, when I switched to port 465 it worked with ssl!

@joeaudette
Copy link

Thanks for your great support!

@mogarick
Copy link

Hi @joeaudette and @jstedfast!
Could you please share example code about using the MailKit to send email with .Net core CLR? I'm newbie with .Net platform (started with .Net 5/core just a week ago. I come from Java, PHP & JS world) and developing in Mac OSX with VS Code.

Thank you in advance!!

@joeaudette
Copy link

@mogarick
Copy link

Thank you @joeaudette .

I'll check it out. I the mean time, I opened an issue (#293) because I'm having a System.Net.Security assembly not found or something like that. Do you have any idea why this could be happening?

Thank you!

@michielpost
Copy link

I can't install MailKit in a ASP.Net 5 Class Library that targets the framework dotnet5.4.
I can install it in a ASP.net 5 website, because webapps target dnx451 and dnxcore50 framework. But class libraries have the frameworks net451 and dotnet5.4.

The dependency MailKit 1.3.0-beta6 in project MyProject.Services does not support framework .NETPlatform,Version=v5.4.

Can you add support for that?

@Maxwe11
Copy link

Maxwe11 commented Feb 25, 2016

I can't install MailKit in a ASP.Net 5 Class Library that targets the framework dotnet5.4.

#298

@jstedfast
Copy link
Owner

@michielpost Unfortunately, dotnet54 is missing System.Net.Sockets (and I think a few other APIs) that would make it impossible to support MailKit on.

Perhaps I can try adding support for net451, though.

@jstedfast
Copy link
Owner

FWIW, if you bump your class library to dotnet5.5, you can install MailKit.

@michielpost
Copy link

Thanks. I thought dnxcore50 supported exactly the same as dotnet5.4. Using dotnet5.5 now and that works. Didn't know that, thanks!

@Ciantic
Copy link

Ciantic commented May 3, 2016

I think the project needs to update for RC2 to "netstandard", old name was "dotnet".

Also when changing tfm to netstandard1.x, the core packages need to be updated from here: https://github.com/davidfowl/NetStandard/blob/master/packages/corefx.json - that is curated list of RC2 core packages.

@joeaudette
Copy link

rc2 has not been released yet

@ssg
Copy link

ssg commented Jun 30, 2016

It got released yesterday.

@jstedfast
Copy link
Owner

Yep, I know. I'll make a new release this weekend when I have enough time to sit down and install all of the updates :)

@joeaudette
Copy link

I've already updated my projects to ASP.NET Core RTM, and MailKit/MimeKit seem to be working fine for me, I'm able to send email.

@jstedfast
Copy link
Owner

Hey guys, I ended up installing the Core updates last night and was able to make updated releases of MimeKit and MailKit 1.4.0 this morning to nuget.org. Enjoy! :)

@joeaudette
Copy link

Awesome! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants