From 6ff753745f1b0bed2b3425bfff4591d3d245d54f Mon Sep 17 00:00:00 2001 From: shove Date: Wed, 24 Aug 2022 01:50:41 +0800 Subject: [PATCH] smtp: send mail to multiple recipients. #15508 (#15509) --- vlib/net/smtp/smtp.v | 12 +++++++----- vlib/net/smtp/smtp_test.v | 8 ++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/vlib/net/smtp/smtp.v b/vlib/net/smtp/smtp.v index 2a114ca831..cd0974885e 100644 --- a/vlib/net/smtp/smtp.v +++ b/vlib/net/smtp/smtp.v @@ -216,8 +216,10 @@ fn (mut c Client) send_mailfrom(from string) ? { } fn (mut c Client) send_mailto(to string) ? { - c.send_str('RCPT TO: <$to>\r\n')? - c.expect_reply(.action_ok)? + for rcpt in to.split(';') { + c.send_str('RCPT TO: <$rcpt>\r\n')? + c.expect_reply(.action_ok)? + } } fn (mut c Client) send_data() ? { @@ -231,9 +233,9 @@ fn (mut c Client) send_body(cfg Mail) ? { nonascii_subject := cfg.subject.bytes().any(it < u8(` `) || it > u8(`~`)) mut sb := strings.new_builder(200) sb.write_string('From: $cfg.from\r\n') - sb.write_string('To: <$cfg.to>\r\n') - sb.write_string('Cc: <$cfg.cc>\r\n') - sb.write_string('Bcc: <$cfg.bcc>\r\n') + sb.write_string('To: <${cfg.to.split(';').join('>; <')}>\r\n') + sb.write_string('Cc: <${cfg.cc.split(';').join('>; <')}>\r\n') + sb.write_string('Bcc: <${cfg.bcc.split(';').join('>; <')}>\r\n') sb.write_string('Date: $date\r\n') if nonascii_subject { // handle UTF-8 subjects according RFC 1342 diff --git a/vlib/net/smtp/smtp_test.v b/vlib/net/smtp/smtp_test.v index 9c4732654a..3002e32e76 100644 --- a/vlib/net/smtp/smtp_test.v +++ b/vlib/net/smtp/smtp_test.v @@ -123,3 +123,11 @@ fn test_smtp_implicit_ssl() { assert client.is_open && client.encrypted } + +fn test_smtp_multiple_recipients() ? { + $if !network ? { + return + } + + assert true +}