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

Add ability to set Sender for mail #375

Closed
wants to merge 3 commits into from

Conversation

johnwc
Copy link

@johnwc johnwc commented Feb 27, 2024

Consolidated target frameworks for libraries and referenced local projects over public packages.

Added a Sender(...) method to be able to set the Sender property of the MailMessage. #374
Have From() override default global From. #321

@johnwc
Copy link
Author

johnwc commented Feb 27, 2024

@jamesmh can you please review

@johnwc
Copy link
Author

johnwc commented Mar 4, 2024

@jamesmh don't mean to be a bother, but we are needing this for one of our up coming releases.

Copy link
Owner

@jamesmh jamesmh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. I've left some feedback on some code changes that we'll have to revert so that the package doesn't break, some extra tests, and then some thinking on how this breaks a public API.

Feel free to make the code changes and throw some thoughts down around the API versioning concerns. Not sure what to do ATM but open to suggestions.

Thanks 🙂

Comment on lines +26 to +29
<ItemGroup>
<ProjectReference Include="..\..\Coravel\Coravel.csproj" />
</ItemGroup>

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Coravel.Cache.Database.Core is a nuget package, we can't reference another project this way. It's unfortunate, but nuget doesn't support bringing in project references into the final published binary.

So this would actually break at either publish or runtime since the Coravel package would be missing.

We'd have to revert this back to the PackageReference.

Copy link
Author

Choose a reason for hiding this comment

The 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>

@@ -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" />
Copy link
Owner

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?

Copy link
Author

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?

</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Coravel.Cache.Database.Core\Coravel.Cache.Database.Core.csproj" />
Copy link
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Author

@johnwc johnwc Sep 20, 2024

Choose a reason for hiding this comment

The 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

Expected

projectB.dll should be in the .nupkg along with projectA.dll

Actual

projectB is still a package reference, not a DLL included in the package.

@@ -22,4 +18,12 @@
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
Copy link
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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" />
Copy link
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same response as above.

@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>.net6.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
Copy link
Owner

Choose a reason for hiding this comment

The 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 .net6 due to features that exist in .net6 and not in .netstandard2.1.

Copy link
Author

Choose a reason for hiding this comment

The 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.

previousTick = nextTick;
}
}
namespace Coravel.Scheduling.Schedule
Copy link
Owner

Choose a reason for hiding this comment

The 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 👍

Copy link
Author

Choose a reason for hiding this comment

The 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

@@ -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());
Copy link
Owner

Choose a reason for hiding this comment

The 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 🙂.

Copy link
Author

Choose a reason for hiding this comment

The 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

@@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The 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 sender was dealt with successfully?

Copy link
Author

Choose a reason for hiding this comment

The 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.

@@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also add some tests against the subject in GeneralMailTests and SmtpMailerTests?

Copy link
Author

@johnwc johnwc Mar 11, 2024

Choose a reason for hiding this comment

The 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? 🙂

@jamesmh
Copy link
Owner

jamesmh commented Sep 20, 2024

This exists in Mailer 6.0.0 now via other changes. Documentation is up to date too if helpful -> https://docs.coravel.net/Mailing/#sender

@jamesmh jamesmh closed this Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants