Skip to content

Commit 4f5d0fc

Browse files
author
Jicheng Lu
committed
extend to email address list
1 parent 7e86057 commit 4f5d0fc

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailSenderFn.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public HandleEmailSenderFn(
2929
public async Task<bool> Execute(RoleDialogModel message)
3030
{
3131
var args = JsonSerializer.Deserialize<LlmContextIn>(message.FunctionArgs, _options.JsonSerializerOptions);
32-
var recipient = args?.ToAddress;
32+
var recipients = args?.ToAddresses?.Where(x => !string.IsNullOrWhiteSpace(x)) ?? [];
3333
var body = args?.Content;
3434
var subject = args?.Subject;
3535
var isNeedAttachments = args?.IsNeedAttachemnts ?? false;
@@ -39,7 +39,12 @@ public async Task<bool> Execute(RoleDialogModel message)
3939
{
4040
var mailMessage = new MimeMessage();
4141
mailMessage.From.Add(new MailboxAddress(_emailSettings.Name, _emailSettings.EmailAddress));
42-
mailMessage.To.Add(new MailboxAddress("", recipient));
42+
43+
foreach (var recipient in recipients)
44+
{
45+
mailMessage.To.Add(new MailboxAddress("", recipient));
46+
}
47+
4348
mailMessage.Subject = subject;
4449
bodyBuilder.TextBody = body;
4550

@@ -53,7 +58,7 @@ public async Task<bool> Execute(RoleDialogModel message)
5358
var response = await SendEmailBySMTP(mailMessage);
5459
message.Content = response;
5560

56-
_logger.LogWarning($"Email successfully send over to {recipient}. Email Subject: {subject} [{response}]");
61+
_logger.LogWarning($"Email successfully send over to {string.Join(",", recipients)}. Email Subject: {subject} [{response}]");
5762
return true;
5863
}
5964
catch (Exception ex)

src/Plugins/BotSharp.Plugin.EmailHandler/LlmContexts/LlmContextIn.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ namespace BotSharp.Plugin.EmailHandler.LlmContexts;
44

55
public class LlmContextIn
66
{
7-
[JsonPropertyName("to_address")]
8-
public string? ToAddress { get; set; }
7+
[JsonPropertyName("to_address_list")]
8+
public IEnumerable<string>? ToAddresses { get; set; }
99

1010
[JsonPropertyName("email_content")]
1111
public string? Content { get; set; }

src/Plugins/BotSharp.Plugin.EmailHandler/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/util-email-handle_email_sender.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
"parameters": {
55
"type": "object",
66
"properties": {
7-
"to_address": {
8-
"type": "string",
9-
"description": "The email address to which the email should be sent to. It needs to be a valid email address in the correct string format."
7+
"to_address_list": {
8+
"type": "array",
9+
"description": "The email addresses to which the email should be sent. Each item needs to be a valid and unique email address in the correct string format.",
10+
"items": {
11+
"type": "string"
12+
}
1013
},
1114
"email_content": {
1215
"type": "string",
@@ -21,6 +24,6 @@
2124
"description": "If the user request to send email with attachemnt(s) or file(s), then this value should be True. Otherwise, this value should be False."
2225
}
2326
},
24-
"required": [ "to_address", "email_content", "subject", "is_need_attachments" ]
27+
"required": [ "to_address_list", "email_content", "subject", "is_need_attachments" ]
2528
}
2629
}

0 commit comments

Comments
 (0)