Open bearsystems opened 5 years ago
I figured it out - I added the follwoing:
Email.DefaultSender = new SmtpSender(new System.Net.Mail.SmtpClient() { Host = "localhost", Port = 25 });
I had similar troubles with this issue on localhost. Is there a reason that the Startup code doesn't work on localhost? Is there something missing from the documentation?
AddSmtpSender doesn't set the DefaultSender of Email
Should this be opened as a separate issue?
I am getting the same issue using the SendGridSender on localhost.
IOException: The specified path is invalid : '\\2019-03-27_10-36-28_153' System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle) System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options) System.IO.FileStream..ctor(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options) FluentEmail.Core.Defaults.SaveToDiskSender.SaveEmailToDisk(IFluentEmail email) FluentEmail.Core.Defaults.SaveToDiskSender.SendAsync(IFluentEmail email, Nullable<CancellationToken> token) FluentEmail.Core.Email.SendAsync(Nullable<CancellationToken> token)
Whats the status on this - does any have a fix?
The same issue applies for AddMailKitSender, which means my startup looks like this:
var smtpClientOptions = new SmtpClientOptions
{
UseSsl = EmailSettings.UseSsl,
Password = EmailSettings.Password,
Port = EmailSettings.Port,
Server = EmailSettings.Server,
User = EmailSettings.User,
UsePickupDirectory = false,
RequiresAuthentication = !string.IsNullOrEmpty(EmailSettings.User)
};
services.AddFluentEmail(EmailSettings.FromAddress).AddRazorRenderer().AddMailKitSender(smtpClientOptions);
Email.DefaultRenderer = new RazorRenderer();
Email.DefaultSender = new MailKitSender(smtpClientOptions);
It seems a bit redundant to have to do both .AddRazorRender and .AddMailKitSender followed by then setting them as the default.
Perhaps the simple API change here is an overload on the extension which allows you to add the Sender/Renderer and set it as the default in one call.
👍 Same issue, surely these calls can be made more concise
Just don't use static class "Email" on your controler, but use an instance of "IFluentEmail" via DI.
Then use
await emailService .To(recipient, "bob") .Subject("hows it going bob") .Body("yo bob, long time no see!") .SendAsync();
And it will work :)
Hi Everyone, this appears to have just bitten me too.... been roaming around for a few days trying to work out what the issue is, and finally I stumble across this.
Brand new ASP.Net core application (Using Rider) , added this in my startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services
.AddFluentEmail("emailtestapp@digital-solutions.local")
.AddRazorRenderer()
.AddSmtpSender("mailbox.digital-solutions.local", 25);
}
Only to find that neither the razor renderer or SMTP sender are actually registered as default.
Actual send code in my action is:
@page "/"
@using FluentEmail.Core
@using FluentEmail.Razor
<h1>Serverside Blazor</h1>
<button @onclick="SendEmail" class="btn btn-primary">Send an Email</button>
@code
{
private void SendEmail()
{
var template = "Dear @Model.Name, You are totally @Model.Compliment.";
var email = Email
.From("shawty.d.ds@googlemail.com")
.To("shawty@shawty.me.uk")
.Subject("Fluent Email test")
.UsingTemplate(template, new { Name = "Shawty", Compliment = "Awesome" })
.Send();
}
}
Once I realised that the sender & renderer where not set up as expected, I added in my own call to set the renderer
Email.DefaultRenderer = new RazorRenderer();
Just before the template line in the above code, and now I'm faced with a new problem that throws an exception every time it tries to render the razor template now:
The assembly in question is most definately not missing, I've checked that and also forced a copy to install using NuGet
I suspect however that this most recent exception, is a separate issue to what's being reported here, so I will in due course once I finish trying some other resolutions, raise that as a separate issue.
The documentation however, does need to be more clear, as it leads to the expectation that all that is needed are the lines in startup and off we go, this is the reason I choose to investigate fluent email over something like mailkit.
I'm having the same issue with FluentEmail.Core on mobile. Getting the invalid path error message. My code is just
await Email
.To(recipient, "bob")
.Subject("hows it going bob")
.Body("yo bob, long time no see!")
.SendAsync();
I don't know if I'm missing something or I just can't use core?
Try running visual studio as administrator and testing the project. This solves the write to disk issue.
Turns out the issue is with the default sender. I followed the steps in the documentation but this did not set the default sender for FluentEmail. This worked:
SmtpClient smtp = new SmtpClient
{
//smtp Server address
Host = "mailserveraddress",
UseDefaultCredentials = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
// Enter here that you are sending smtp User name and password for the server
Credentials = new NetworkCredential("username", "password"),
EnableSsl = true
};
Email.DefaultSender = new SmtpSender(smtp);
var email = await Email
.From(from)
.To(toEmail, toEmail)
.Subject(subject)
.Body(message)
.SendAsync();
reference: https://ofstack.com/asp.net/44195/net-core-sample-code-for-sending-mail-using-fluentemail.html
Just rejected this library based on this issue. If you can't even get through sending one email without working around bugs in such basic behavior, I'm not about to trust this library with anything important.
Can you try my fork?
https://github.com/jcamp-code/FluentEmail
If it still happens with this version, submit an issue there and I'll take a look. I love this library and want to keep it going.
I am using a very basic version with the call:
var email = Email .From("support@myemail.com") .To("support@myemail.com") .Subject("Errors founds in " + _context.LocationName) .Body(strMyText, false).Send();
This is my setup in my Startup.cs file:
services.AddFluentEmail("support@bear.systems").AddSmtpSender("localhost", 25);
Whenever I send the file, I am getting the following error:
The specified path is invalid : '\\2018-11-29_09-17-50_163' at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle) at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) at FluentEmail.Core.Defaults.SaveToDiskSender.SaveEmailToDisk(IFluentEmail email) at FluentEmail.Core.Defaults.SaveToDiskSender.SendAsync(IFluentEmail email, Nullable
1 token) at FluentEmail.Core.Defaults.SaveToDiskSender.Send(IFluentEmail email, Nullable1 token) at FluentEmail.Core.Email.Send(Nullable
1 token)`