Merge branch 'devel' of github.com:nim-lang/Nim into devel
This commit is contained in:
commit
3f7694d08a
1 changed files with 40 additions and 16 deletions
|
|
@ -256,24 +256,48 @@ proc close*(smtp: AsyncSmtp) {.async.} =
|
||||||
smtp.sock.close()
|
smtp.sock.close()
|
||||||
|
|
||||||
when not defined(testing) and isMainModule:
|
when not defined(testing) and isMainModule:
|
||||||
#var msg = createMessage("Test subject!",
|
# To test with a real SMTP service, create a smtp.ini file, e.g.:
|
||||||
# "Hello, my name is dom96.\n What\'s yours?", @["dominik@localhost"])
|
# username = ""
|
||||||
#echo(msg)
|
# password = ""
|
||||||
|
# smtphost = "smtp.gmail.com"
|
||||||
|
# port = 465
|
||||||
|
# use_tls = true
|
||||||
|
# sender = ""
|
||||||
|
# recipient = ""
|
||||||
|
|
||||||
#var smtpConn = connect("localhost", Port 25, false, true)
|
import parsecfg
|
||||||
#smtpConn.sendmail("root@localhost", @["dominik@localhost"], $msg)
|
|
||||||
|
|
||||||
#echo(decode("a17sm3701420wbe.12"))
|
proc `[]`(c: Config, key: string): string = c.getSectionValue("", key)
|
||||||
proc main() {.async.} =
|
|
||||||
var client = newAsyncSmtp("smtp.gmail.com", Port(465), true)
|
let
|
||||||
|
conf = loadConfig("smtp.ini")
|
||||||
|
msg = createMessage("Hello from Nim's SMTP!",
|
||||||
|
"Hello!\n Is this awesome or what?", @[conf["recipient"]])
|
||||||
|
|
||||||
|
assert conf["smtphost"] != ""
|
||||||
|
|
||||||
|
proc async_test() {.async.} =
|
||||||
|
let client = newAsyncSmtp(
|
||||||
|
conf["smtphost"],
|
||||||
|
conf["port"].parseInt.Port,
|
||||||
|
conf["use_tls"].parseBool
|
||||||
|
)
|
||||||
await client.connect()
|
await client.connect()
|
||||||
await client.auth("johndoe", "foo")
|
await client.auth(conf["username"], conf["password"])
|
||||||
var msg = createMessage("Hello from Nim's SMTP!",
|
await client.sendMail(conf["sender"], @[conf["recipient"]], $msg)
|
||||||
"Hello!!!!.\n Is this awesome or what?",
|
|
||||||
@["blah@gmail.com"])
|
|
||||||
echo(msg)
|
|
||||||
await client.sendMail("blah@gmail.com", @["blah@gmail.com"], $msg)
|
|
||||||
|
|
||||||
await client.close()
|
await client.close()
|
||||||
|
echo "async email sent"
|
||||||
|
|
||||||
waitFor main()
|
proc sync_test() =
|
||||||
|
var smtpConn = connect(
|
||||||
|
conf["smtphost"],
|
||||||
|
conf["port"].parseInt.Port,
|
||||||
|
conf["use_tls"].parseBool,
|
||||||
|
true, # debug
|
||||||
|
)
|
||||||
|
smtpConn.auth(conf["username"], conf["password"])
|
||||||
|
smtpConn.sendmail(conf["sender"], @[conf["recipient"]], $msg)
|
||||||
|
echo "sync email sent"
|
||||||
|
|
||||||
|
waitFor async_test()
|
||||||
|
sync_test()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue