-
-
Notifications
You must be signed in to change notification settings - Fork 259
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
Add ability to set Sender for mail #375
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<PackageId>Coravel.Cache.Database.Core</PackageId> | ||
<Version>2.0.2</Version> | ||
<Authors>James Hickey</Authors> | ||
|
@@ -19,9 +19,12 @@ | |
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Coravel" Version="3.0.0" /> | ||
<PackageReference Include="Dapper" Version="1.60.6" /> | ||
<PackageReference Include="Dapper" Version="2.1.28" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Coravel\Coravel.csproj" /> | ||
</ItemGroup> | ||
|
||
Comment on lines
+26
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because So this would actually break at either publish or runtime since the We'd have to revert this back to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We reference our packages like this, and all of our packages show that they have dependencies to the library that is Project Referenced. I don't think I have ever not seen that. Looking at my local nupkg of this library, so does yours. Am I not understanding what you are referring to? <?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Coravel.Cache.Database.Core</id>
<version>2.0.2</version>
<title>Coravel Database Cache Driver Shared Library</title>
<authors>James Hickey</authors>
<license type="expression">MIT</license>
<licenseUrl>https://licenses.nuget.org/MIT</licenseUrl>
<projectUrl>https://github.com/jamesmh/coravel</projectUrl>
<description>Core tools for Coravel database cache drivers</description>
<tags>netcore coravel caching database</tags>
<repository type="git" url="https://github.com/jamesmh/coravel" commit="0ec0e2d0ed24f99c5ab4b24a8fd575114b4f3b7b" />
<dependencies>
<group targetFramework=".NETStandard2.1">
<dependency id="Coravel" version="5.0.2" exclude="Build,Analyzers" />
<dependency id="Dapper" version="2.1.28" exclude="Build,Analyzers" />
<dependency id="Newtonsoft.Json" version="12.0.2" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
</package> |
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using System.Data.Common; | ||
using System.Data.SqlClient; | ||
|
||
namespace Coravel.Cache.Database.Core | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,14 @@ | |
|
||
<ItemGroup> | ||
<PackageReference Include="npgsql" Version="4.0.7" /> | ||
<PackageReference Include="Coravel.Cache.Database.Core" version="2.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Coravel.Cache.Database.Core\Coravel.Cache.Database.Core.csproj" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, you can't use project references in nuget like this. It will break. We'll have to revert this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, need clarification on what you are referring to, as my understanding is that it works OoB as correct dependency in built package. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just coming back to this to explain briefly. If we published this as a nuget package, everything would build fine and publish fine. But, the consumer would get an error when consuming the nuget package. It's been a debate for years and is currently ongoing: NuGet/Home#3891 There have been some "hacks" - some I've tried when I started this project years ago. But a hack is a hack - and it's not intuitive, ideal, implicit knowledge, etc. and I didn't want to add risk by using a hack. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you see my other comment prior, you will notice that when the packages get built and packaged, the other project reference packages get added as nuget package dependencies. The issue you shared is something different, they want the DLL from the referenced project to be included in the parent project's nuget package and not as a nuget dependency. You do not want this; other libraries need to stay as other nuget packages. And if an outside project references the parent nuget, then the nuget restore will pull down all the dependent libraries which would include your other DLLs. If you added the DLL as another file to the nuget, then you would have issues with other packages that also have it included in thier nuget, but have other version etc... It would not allow nuget to do what it does best and maintain nuget version compatibility between packages. Reference from the issue ExpectedprojectB.dll should be in the .nupkg along with projectA.dll ActualprojectB is still a package reference, not a DLL included in the package. |
||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<PackageId>Coravel.Cache.PostgreSQL</PackageId> | ||
<Version>2.0.2</Version> | ||
<Authors>James Hickey</Authors> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Coravel.Cache.Database.Core" version="2.0.0" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<PackageId>Coravel.Cache.SQLServer</PackageId> | ||
<Version>2.0.2</Version> | ||
<Authors>James Hickey</Authors> | ||
|
@@ -22,4 +18,12 @@ | |
<NoWarn>$(NoWarn);1591</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this new package? I don't see a change to warrant this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need a reference to this specific to use the version that does not have security vulnerabilities. It is already a dependency of the package, just need to push it to latest to avoid security issues. |
||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Coravel.Cache.Database.Core\Coravel.Cache.Database.Core.csproj" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't use project references, we have to stick to package references. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same response as above. |
||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,6 @@ public interface IMailer | |
{ | ||
Task<string> RenderAsync<T>(Mailable<T> mailable); | ||
Task SendAsync<T>(Mailable<T> mailable); | ||
Task SendAsync(string message, string subject, IEnumerable<MailRecipient> to, MailRecipient from, MailRecipient replyTo, IEnumerable<MailRecipient> cc, IEnumerable<MailRecipient> bcc, IEnumerable<Attachment> attachments = null); | ||
Task SendAsync(string message, string subject, IEnumerable<MailRecipient> to, MailRecipient from, MailRecipient replyTo, MailRecipient sender, IEnumerable<MailRecipient> cc, IEnumerable<MailRecipient> bcc, IEnumerable<Attachment> attachments = null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this breaks a public API. Anyone using this piece of Coravel will have their code broken if this gets published... So we'd need to think about the impact, potential alternatives, etc. At the moment I'm not sure... first thought is if we put this at the end of the params then we can make it an optional param and not break existing usages. Or, we could make a new method with an updated params here, depreciate the "old" one, and come up with some kind of versioning/sunsetting strategy here. Open to suggestions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would go with the new/old with soft |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ public async Task SendAsync<T>(Mailable<T> mailable) | |
await mailable.SendAsync(this._renderer, this); | ||
} | ||
|
||
public async Task SendAsync(string message, string subject, IEnumerable<MailRecipient> to, MailRecipient from, MailRecipient replyTo, IEnumerable<MailRecipient> cc, IEnumerable<MailRecipient> bcc, IEnumerable<Attachment> attachments = null) | ||
public async Task SendAsync(string message, string subject, IEnumerable<MailRecipient> to, MailRecipient from, MailRecipient replyTo, MailRecipient sender, IEnumerable<MailRecipient> cc, IEnumerable<MailRecipient> bcc, IEnumerable<Attachment> attachments = null) | ||
{ | ||
var mail = new MimeMessage(); | ||
|
||
|
@@ -66,6 +66,11 @@ public async Task SendAsync(string message, string subject, IEnumerable<MailReci | |
SetReplyTo(replyTo, mail); | ||
} | ||
|
||
if (sender != null) | ||
{ | ||
SetSender(sender, mail); | ||
} | ||
|
||
using (var client = new SmtpClient()) | ||
{ | ||
client.ServerCertificateValidationCallback = this._certCallback; | ||
|
@@ -121,14 +126,19 @@ private static void SetRecipients(IEnumerable<MailRecipient> to, MimeMessage mai | |
|
||
private void SetFrom(MailRecipient @from, MimeMessage mail) | ||
{ | ||
mail.From.Add(AsMailboxAddress(this._globalFrom ?? @from)); | ||
mail.From.Add(AsMailboxAddress(@from ?? this._globalFrom)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting change. I would leave out of this MR since it would require, I think, a different discussion around what the expect behavior should be, etc. Right now, this is the expected behavior and many users could rely on this usage. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a change from one of your previous issues that you ok'ed and requested them to create a PR for this work. They did not, so I added it to this one. As we as well were very confused on why when we manually set the from address in a single mail, it would always use the global default. I mentioned this in the PR notes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also debate that you cannot use this feature without this change, because if you apply the global from, you can never set the from in the mail. |
||
} | ||
|
||
private static void SetReplyTo(MailRecipient replyTo, MimeMessage mail) | ||
{ | ||
mail.ReplyTo.Add(AsMailboxAddress(replyTo)); | ||
} | ||
|
||
private static void SetSender(MailRecipient sender, MimeMessage mail) | ||
{ | ||
mail.Sender = AsMailboxAddress(sender); | ||
} | ||
|
||
private static MailboxAddress AsMailboxAddress(MailRecipient recipient) => | ||
new MailboxAddress(recipient.Name, recipient.Email); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>.net6.0</TargetFramework> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't run this, but pretty sure that this would break when running tests or at runtime. We need to target There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 2 needed code style changes below were made to be able to target the netstandard. |
||
<PackageId>Coravel</PackageId> | ||
<Version>5.0.2</Version> | ||
<Authors>James Hickey</Authors> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,44 +3,46 @@ | |
using System.Linq; | ||
using Coravel.Scheduling.Schedule.Helpers; | ||
|
||
namespace Coravel.Scheduling.Schedule; | ||
|
||
public class EnsureContinuousSecondTicks | ||
{ | ||
private DateTime previousTick; | ||
|
||
public EnsureContinuousSecondTicks(DateTime firstTick) | ||
{ | ||
previousTick = firstTick; | ||
} | ||
|
||
/// <summary> | ||
/// Give this method when the next tick occurs and it will return any intermediary ticks that should | ||
/// have existed been the stored previous tick and the next one. | ||
/// </summary> | ||
/// <param name="nextTick"></param> | ||
/// <returns></returns> | ||
public IEnumerable<DateTime> GetTicksBetweenPreviousAndNext(DateTime nextTick) | ||
{ | ||
// Starting at previousTick, we move ahead one second a time and record the next time until we get to the "nextTick". | ||
// Then we check if there are any missed ticks between the two. | ||
List<DateTime> missingTicks = null; // We don't want to commit any memory until we know for sure there's at least 1 missed tick. | ||
DateTime nextTickToTest = previousTick.PreciseUpToSecond().AddSeconds(1); | ||
while (nextTickToTest < nextTick.PreciseUpToSecond()) | ||
{ | ||
if (missingTicks is null) | ||
{ | ||
missingTicks = new List<DateTime>(); | ||
} | ||
missingTicks.Add(nextTickToTest); | ||
nextTickToTest = nextTickToTest.PreciseUpToSecond().AddSeconds(1); | ||
} | ||
|
||
return missingTicks ?? Enumerable.Empty<DateTime>(); | ||
} | ||
|
||
public void SetNextTick(DateTime nextTick) | ||
{ | ||
previousTick = nextTick; | ||
} | ||
} | ||
namespace Coravel.Scheduling.Schedule | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we undo this file's styling changes? Don't think it's necessary and I think would be best in a dedicated "styling fix" PR vs. combining logic changes, styling changes, bug fix, etc. in one PR 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was causing it to need to point to .net6, with this style revert, it now can target .netstandard |
||
{ | ||
|
||
public class EnsureContinuousSecondTicks | ||
{ | ||
private DateTime previousTick; | ||
|
||
public EnsureContinuousSecondTicks(DateTime firstTick) | ||
{ | ||
previousTick = firstTick; | ||
} | ||
|
||
/// <summary> | ||
/// Give this method when the next tick occurs and it will return any intermediary ticks that should | ||
/// have existed been the stored previous tick and the next one. | ||
/// </summary> | ||
/// <param name="nextTick"></param> | ||
/// <returns></returns> | ||
public IEnumerable<DateTime> GetTicksBetweenPreviousAndNext(DateTime nextTick) | ||
{ | ||
// Starting at previousTick, we move ahead one second a time and record the next time until we get to the "nextTick". | ||
// Then we check if there are any missed ticks between the two. | ||
List<DateTime> missingTicks = null; // We don't want to commit any memory until we know for sure there's at least 1 missed tick. | ||
DateTime nextTickToTest = previousTick.PreciseUpToSecond().AddSeconds(1); | ||
while (nextTickToTest < nextTick.PreciseUpToSecond()) | ||
{ | ||
if (missingTicks is null) | ||
{ | ||
missingTicks = new List<DateTime>(); | ||
} | ||
missingTicks.Add(nextTickToTest); | ||
nextTickToTest = nextTickToTest.PreciseUpToSecond().AddSeconds(1); | ||
} | ||
|
||
return missingTicks ?? Enumerable.Empty<DateTime>(); | ||
} | ||
|
||
public void SetNextTick(DateTime nextTick) | ||
{ | ||
previousTick = nextTick; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,7 @@ public async Task InvokeScheduledEvent(CancellationToken cancellationToken) | |
} | ||
else | ||
{ | ||
await using AsyncServiceScope scope = new(this._scopeFactory.CreateAsyncScope()); | ||
await using AsyncServiceScope scope = new AsyncServiceScope(this._scopeFactory.CreateAsyncScope()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why this was formatted this way? Could we revert this one please 🙂. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was causing it to need to point to .net6, with this style revert, it now can target .netstandard |
||
if (GetInvocable(scope.ServiceProvider) is IInvocable invocable) | ||
{ | ||
if (invocable is ICancellableInvocable cancellableInvokable) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ public class CustomMailerTests | |
[Fact] | ||
public async Task CustomMailerSucessful() | ||
{ | ||
async Task SendMailCustom(string message, string subject, IEnumerable<MailRecipient> to, MailRecipient from, MailRecipient replyTo, IEnumerable<MailRecipient> cc, IEnumerable<MailRecipient> bcc, IEnumerable<Attachment> attachments) | ||
async Task SendMailCustom(string message, string subject, IEnumerable<MailRecipient> to, MailRecipient from, MailRecipient replyTo, MailRecipient sender, IEnumerable<MailRecipient> cc, IEnumerable<MailRecipient> bcc, IEnumerable<Attachment> attachments) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we also add some tests against the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't think I changed the subject, is this just an ad hoc request to add this while I am doing the other test? 🙂 |
||
{ | ||
Assert.Equal("test", subject); | ||
Assert.Equal("from@test.com", from.Email); | ||
|
@@ -41,7 +41,7 @@ await mailer.SendAsync( | |
[Fact] | ||
public async Task CustomMailer_GlobalFrom() | ||
{ | ||
async Task SendMailCustom(string message, string subject, IEnumerable<MailRecipient> to, MailRecipient from, MailRecipient replyTo, IEnumerable<MailRecipient> cc, IEnumerable<MailRecipient> bcc, IEnumerable<Attachment> attachments) | ||
async Task SendMailCustom(string message, string subject, IEnumerable<MailRecipient> to, MailRecipient from, MailRecipient replyTo, MailRecipient sender, IEnumerable<MailRecipient> cc, IEnumerable<MailRecipient> bcc, IEnumerable<Attachment> attachments) | ||
{ | ||
Assert.Equal("global@test.com", from.Email); | ||
Assert.Equal("Global", from.Name); | ||
|
@@ -66,7 +66,7 @@ await mailer.SendAsync( | |
[Fact] | ||
public async Task CustomMailer_Render() | ||
{ | ||
async Task SendMailCustom(string message, string subject, IEnumerable<MailRecipient> to, MailRecipient from, MailRecipient replyTo, IEnumerable<MailRecipient> cc, IEnumerable<MailRecipient> bcc, IEnumerable<Attachment> attachments) | ||
async Task SendMailCustom(string message, string subject, IEnumerable<MailRecipient> to, MailRecipient from, MailRecipient replyTo, MailRecipient sender, IEnumerable<MailRecipient> cc, IEnumerable<MailRecipient> bcc, IEnumerable<Attachment> attachments) | ||
{ | ||
await Task.CompletedTask; | ||
}; | ||
|
@@ -92,7 +92,7 @@ async Task SendMailCustom(string message, string subject, IEnumerable<MailRecipi | |
[Fact] | ||
public async Task CustomMailerHasAttachments() | ||
{ | ||
async Task SendMailCustom(string message, string subject, IEnumerable<MailRecipient> to, MailRecipient from, MailRecipient replyTo, IEnumerable<MailRecipient> cc, IEnumerable<MailRecipient> bcc, IEnumerable<Attachment> attachments) | ||
async Task SendMailCustom(string message, string subject, IEnumerable<MailRecipient> to, MailRecipient from, MailRecipient replyTo, MailRecipient sender, IEnumerable<MailRecipient> cc, IEnumerable<MailRecipient> bcc, IEnumerable<Attachment> attachments) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just like this test, could we add a new dedicated test to ensure that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will see what I can do to add a test for sender based on this current test. |
||
{ | ||
Assert.Equal(2, attachments.Count()); | ||
Assert.Equal("Attachment 2", attachments.Skip(1).Single().Name); | ||
|
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's the reasoning behind changing the version 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.
Why not, it is a local build depending on the and not a runtime dependency. It is not going to have dependency issue for the consumer. Would we not want to use the latest and greatest updates from a package like Dapper, so to utilize performance and security updates?