test: enable passing username/password through env vars to smtp_test.v
parent
ee46c8075f
commit
97d01a5487
|
@ -139,6 +139,9 @@ fn (c Client) send_ehlo() ? {
|
|||
|
||||
[inline]
|
||||
fn (c Client) send_auth() ? {
|
||||
if c.username.len == 0 {
|
||||
return
|
||||
}
|
||||
mut sb := strings.new_builder(100)
|
||||
sb.write_b(0)
|
||||
sb.write(c.username)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
import smtp
|
||||
import time
|
||||
|
||||
|
@ -18,6 +19,8 @@ fn test_smtp() {
|
|||
client_cfg := smtp.Client{
|
||||
server: 'smtp.mailtrap.io'
|
||||
from: 'dev@vlang.io'
|
||||
username: os.getenv('VSMTP_TEST_USER')
|
||||
password: os.getenv('VSMTP_TEST_PASS')
|
||||
}
|
||||
|
||||
send_cfg := smtp.Mail{
|
||||
|
@ -30,24 +33,19 @@ fn test_smtp() {
|
|||
// `break`. There's an `assert false` after the loop, which will only be called if this loop
|
||||
// is broken from.
|
||||
for {
|
||||
mut client := smtp.new_client(client_cfg) or { break }
|
||||
|
||||
client.send(send_cfg) or { break }
|
||||
mut client := smtp.new_client(client_cfg) or { assert false break }
|
||||
client.send(send_cfg) or { assert false break }
|
||||
// client.send({ send_cfg | body_type: .html, body: '<html><h1>HTML V email!</h1></html>' }) or { break }
|
||||
client.send({ send_cfg | from: 'alexander@vlang.io' }) or { break }
|
||||
client.send({ send_cfg | cc: 'alexander@vlang.io,joe@vlang.io', bcc: 'spytheman@vlang.io' }) or { break }
|
||||
client.send({ send_cfg | date: time.now().add_days(1000) }) or { break }
|
||||
|
||||
client.quit() or { break }
|
||||
|
||||
client.send({ send_cfg | from: 'alexander@vlang.io' }) or { assert false break }
|
||||
client.send({ send_cfg | cc: 'alexander@vlang.io,joe@vlang.io', bcc: 'spytheman@vlang.io' }) or { assert false break }
|
||||
client.send({ send_cfg | date: time.now().add_days(1000) }) or { assert false break }
|
||||
client.quit() or { assert false break }
|
||||
// This call should return an error, since the connection is closed
|
||||
if !fn_errors(client, send_cfg) { break }
|
||||
|
||||
client.reconnect() or { break }
|
||||
client.send(send_cfg) or { break }
|
||||
|
||||
if !fn_errors(client, send_cfg) { assert false break }
|
||||
client.reconnect() or { assert false break }
|
||||
client.send(send_cfg) or { assert false break }
|
||||
assert true
|
||||
return
|
||||
}
|
||||
|
||||
assert false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue