1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

smtp: send mail to multiple recipients. #15508 (#15509)

This commit is contained in:
shove 2022-08-24 01:50:41 +08:00 committed by GitHub
parent 3b42f18dee
commit 6ff753745f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View File

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

View File

@ -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
}