Skip to content

Commit

Permalink
smtp: send mail to multiple recipients. #15508 (#15509)
Browse files Browse the repository at this point in the history
  • Loading branch information
shove70 committed Aug 23, 2022
1 parent 3b42f18 commit 6ff7537
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 7 additions & 5 deletions vlib/net/smtp/smtp.v
Expand Up @@ -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() ? {
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions vlib/net/smtp/smtp_test.v
Expand Up @@ -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
}

0 comments on commit 6ff7537

Please sign in to comment.