diff --git a/docs/en/Emailing.md b/docs/en/Emailing.md index fd9e696b3e..48635b2565 100644 --- a/docs/en/Emailing.md +++ b/docs/en/Emailing.md @@ -62,8 +62,7 @@ namespace MyProject * **subject**: You can set the email subject. * **body**: You can set the email body. * **isBodyHtml**: Indicates whether the email body may contain HTML tags. **Default: true**. -* **attachments**: You can pass a list of `EmailAttachment` to add attachments to the email. -* **extraProperties**: You can pass extra properties and use these properties in your own `IEmailSender` implementation to implement more mail sending features. +* **additionalEmailSendingArgs**: This parameter is used to pass additional arguments to the `IEmailSender` implementation. Include: CC(Carbon copy), a list of `EmailAttachment` and an extra properties. > `IEmailSender` is the suggested way to send emails, since it makes your code provider independent. diff --git a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/AdditionalEmailSendingArgs.cs b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/AdditionalEmailSendingArgs.cs new file mode 100644 index 0000000000..98236d07d5 --- /dev/null +++ b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/AdditionalEmailSendingArgs.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using Volo.Abp.Data; + +namespace Volo.Abp.Emailing; + +public class AdditionalEmailSendingArgs +{ + public List? CC { get; set; } + + public List? Attachments { get; set; } + + public ExtraPropertyDictionary? ExtraProperties { get; set; } +} diff --git a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/BackgroundEmailSendingJob.cs b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/BackgroundEmailSendingJob.cs index f1d2812ae9..ac12ddcead 100644 --- a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/BackgroundEmailSendingJob.cs +++ b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/BackgroundEmailSendingJob.cs @@ -19,11 +19,11 @@ public class BackgroundEmailSendingJob : AsyncBackgroundJob public bool IsBodyHtml { get; set; } = true; - public List? Attachments { get; set; } - - public ExtraPropertyDictionary? ExtraProperties { get; set; } + public AdditionalEmailSendingArgs? AdditionalEmailSendingArgs { get; set; } } diff --git a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/EmailSenderBase.cs b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/EmailSenderBase.cs index 8de9f4c5a1..5f342b2f40 100644 --- a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/EmailSenderBase.cs +++ b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/EmailSenderBase.cs @@ -1,12 +1,10 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Mail; using System.Text; using System.Threading.Tasks; using Volo.Abp.BackgroundJobs; -using Volo.Abp.Data; namespace Volo.Abp.Emailing; @@ -28,29 +26,40 @@ public abstract class EmailSenderBase : IEmailSender BackgroundJobManager = backgroundJobManager; } - public virtual async Task SendAsync(string to, string? subject, string? body, bool isBodyHtml = true, List? attachments = null, ExtraPropertyDictionary? extraProperties = null) + public virtual async Task SendAsync(string to, string? subject, string? body, bool isBodyHtml = true, AdditionalEmailSendingArgs? additionalEmailSendingArgs = null) { - await SendAsync(BuildMailMessage(null, to, subject, body, isBodyHtml, attachments, extraProperties)); + await SendAsync(BuildMailMessage(null, to, subject, body, isBodyHtml, additionalEmailSendingArgs)); } - public virtual async Task SendAsync(string from, string to, string? subject, string? body, bool isBodyHtml = true, List? attachments = null, ExtraPropertyDictionary? extraProperties = null) + public virtual async Task SendAsync(string from, string to, string? subject, string? body, bool isBodyHtml = true, AdditionalEmailSendingArgs? additionalEmailSendingArgs = null) { - await SendAsync(BuildMailMessage(from, to, subject, body, isBodyHtml, attachments, extraProperties)); + await SendAsync(BuildMailMessage(from, to, subject, body, isBodyHtml, additionalEmailSendingArgs)); } - protected virtual MailMessage BuildMailMessage(string? from, string to, string? subject, string? body, bool isBodyHtml = true, List? attachments = null, ExtraPropertyDictionary? extraProperties = null) + protected virtual MailMessage BuildMailMessage(string? from, string to, string? subject, string? body, bool isBodyHtml = true, AdditionalEmailSendingArgs? additionalEmailSendingArgs = null) { var message = from == null ? new MailMessage { To = { to }, Subject = subject, Body = body, IsBodyHtml = isBodyHtml } : new MailMessage(from, to, subject, body) { IsBodyHtml = isBodyHtml }; - if (attachments != null) + if (additionalEmailSendingArgs != null) { - foreach (var attachment in attachments.Where(x => x.File != null)) + if (additionalEmailSendingArgs.Attachments != null) { - var fileStream = new MemoryStream(attachment.File!); - fileStream.Seek(0, SeekOrigin.Begin); - message.Attachments.Add(new Attachment(fileStream, attachment.Name)); + foreach (var attachment in additionalEmailSendingArgs.Attachments.Where(x => x.File != null)) + { + var fileStream = new MemoryStream(attachment.File!); + fileStream.Seek(0, SeekOrigin.Begin); + message.Attachments.Add(new Attachment(fileStream, attachment.Name)); + } + } + + if (additionalEmailSendingArgs.CC != null) + { + foreach (var cc in additionalEmailSendingArgs.CC) + { + message.CC.Add(cc); + } } } @@ -67,11 +76,11 @@ public abstract class EmailSenderBase : IEmailSender await SendEmailAsync(mail); } - public virtual async Task QueueAsync(string to, string subject, string body, bool isBodyHtml = true, List? attachments = null, ExtraPropertyDictionary? extraProperties = null) + public virtual async Task QueueAsync(string to, string subject, string body, bool isBodyHtml = true, AdditionalEmailSendingArgs? additionalEmailSendingArgs = null) { if (!BackgroundJobManager.IsAvailable()) { - await SendAsync(to, subject, body, isBodyHtml, attachments, extraProperties); + await SendAsync(to, subject, body, isBodyHtml, additionalEmailSendingArgs); return; } @@ -82,17 +91,16 @@ public abstract class EmailSenderBase : IEmailSender Subject = subject, Body = body, IsBodyHtml = isBodyHtml, - Attachments = attachments, - ExtraProperties = extraProperties + AdditionalEmailSendingArgs = additionalEmailSendingArgs } ); } - public virtual async Task QueueAsync(string from, string to, string subject, string body, bool isBodyHtml = true, List? attachments = null, ExtraPropertyDictionary? extraProperties = null) + public virtual async Task QueueAsync(string from, string to, string subject, string body, bool isBodyHtml = true, AdditionalEmailSendingArgs? additionalEmailSendingArgs = null) { if (!BackgroundJobManager.IsAvailable()) { - await SendAsync(from, to, subject, body, isBodyHtml, attachments, extraProperties); + await SendAsync(from, to, subject, body, isBodyHtml, additionalEmailSendingArgs); return; } @@ -104,8 +112,7 @@ public abstract class EmailSenderBase : IEmailSender Subject = subject, Body = body, IsBodyHtml = isBodyHtml, - Attachments = attachments, - ExtraProperties = extraProperties + AdditionalEmailSendingArgs = additionalEmailSendingArgs } ); } diff --git a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/IEmailSender.cs b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/IEmailSender.cs index d2952c2d47..64658b0519 100644 --- a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/IEmailSender.cs +++ b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/IEmailSender.cs @@ -1,7 +1,5 @@ -using System.Collections.Generic; -using System.Net.Mail; +using System.Net.Mail; using System.Threading.Tasks; -using Volo.Abp.Data; namespace Volo.Abp.Emailing; @@ -18,8 +16,7 @@ public interface IEmailSender string? subject, string? body, bool isBodyHtml = true, - List? attachments = null, - ExtraPropertyDictionary? extraProperties = null + AdditionalEmailSendingArgs? additionalEmailSendingArgs = null ); /// @@ -31,8 +28,7 @@ public interface IEmailSender string? subject, string? body, bool isBodyHtml = true, - List? attachments = null, - ExtraPropertyDictionary? extraProperties = null + AdditionalEmailSendingArgs? additionalEmailSendingArgs = null ); /// @@ -56,8 +52,7 @@ public interface IEmailSender string subject, string body, bool isBodyHtml = true, - List? attachments = null, - ExtraPropertyDictionary? extraProperties = null + AdditionalEmailSendingArgs? additionalEmailSendingArgs = null ); /// @@ -69,7 +64,6 @@ public interface IEmailSender string subject, string body, bool isBodyHtml = true, - List? attachments = null, - ExtraPropertyDictionary? extraProperties = null + AdditionalEmailSendingArgs? additionalEmailSendingArgs = null ); }