Update how-send-email-nim-2019-08-28.markdown
This commit is contained in:
parent
be0ee9e7ea
commit
fce0d2fe33
|
@ -33,7 +33,7 @@ GMail to accept them. They are:
|
||||||
|
|
||||||
For a more complete example, let's create a `Mailer` type and a constructor:
|
For a more complete example, let's create a `Mailer` type and a constructor:
|
||||||
|
|
||||||
```
|
```nim
|
||||||
# mailer.nim
|
# mailer.nim
|
||||||
import asyncdispatch, logging, smtp, strformat, strutils
|
import asyncdispatch, logging, smtp, strformat, strutils
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ proc newMailer*(address, port, myAddress, myName, username, password: string): M
|
||||||
|
|
||||||
And let's write a `mail` method to send out email:
|
And let's write a `mail` method to send out email:
|
||||||
|
|
||||||
```
|
```nim
|
||||||
proc mail(m: Mailer, to, toName, subject, body: string) {.async.} =
|
proc mail(m: Mailer, to, toName, subject, body: string) {.async.} =
|
||||||
let
|
let
|
||||||
toList = @[fmt"{toName} <{to}>"]
|
toList = @[fmt"{toName} <{to}>"]
|
||||||
|
@ -86,13 +86,13 @@ email provider that offers TLS/SSL-encrypted SMTP support. This also means that
|
||||||
you need to compile this code with `--define: ssl`, so create `config.nims` and
|
you need to compile this code with `--define: ssl`, so create `config.nims` and
|
||||||
add the following:
|
add the following:
|
||||||
|
|
||||||
```
|
```nimscript
|
||||||
--define: ssl
|
--define: ssl
|
||||||
```
|
```
|
||||||
|
|
||||||
Here's a little wrapper using [cligen][cligen]:
|
Here's a little wrapper using [cligen][cligen]:
|
||||||
|
|
||||||
```
|
```nim
|
||||||
when isMailModule:
|
when isMailModule:
|
||||||
import cligen, os
|
import cligen, os
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ when isMailModule:
|
||||||
|
|
||||||
Usage is simple:
|
Usage is simple:
|
||||||
|
|
||||||
```
|
```console
|
||||||
$ nim c -r mailer.nim --help
|
$ nim c -r mailer.nim --help
|
||||||
Usage:
|
Usage:
|
||||||
sendAnEmail [required&optional-params]
|
sendAnEmail [required&optional-params]
|
||||||
|
|
Loading…
Reference in New Issue