| 1 | // vtest build: present_openssl? |
| 2 | // Creator: nedimf (07/2020) |
| 3 | import os |
| 4 | import net.smtp |
| 5 | |
| 6 | fn main() { |
| 7 | println('Hi, this is sample of how to send email trough net.smtp library in V, which is really easy using the net.smtp module.') |
| 8 | println('We are going to create a simple email client, that takes some arguments. and then sends email with an HTML body.') |
| 9 | println('To fully test email sending, I suggest using the mailtrap.io service, which is free and acts like a really nice mail server sandbox.') |
| 10 | println('') |
| 11 | println('V Email client') |
| 12 | println('') |
| 13 | mailserver := os.input('Mail server: ') |
| 14 | mailport := os.input('Mail server port: ').int() |
| 15 | println('Login') |
| 16 | username := os.input('Username: ') |
| 17 | password := os.input('Password: ') |
| 18 | from := os.input('From: ') |
| 19 | to := os.input('To: ') |
| 20 | subject := os.input('Subject: ') |
| 21 | body := os.input('Body: ') |
| 22 | client_cfg := smtp.Config{ |
| 23 | server: mailserver |
| 24 | from: from |
| 25 | port: mailport |
| 26 | username: username |
| 27 | password: password |
| 28 | } |
| 29 | send_cfg := smtp.Mail{ |
| 30 | to: to |
| 31 | subject: subject |
| 32 | body_type: .html |
| 33 | body: body |
| 34 | } |
| 35 | mut client := smtp.new_client(client_cfg) or { panic('Error with configuring smtp: ${err}') } |
| 36 | client.send(send_cfg) or { panic('Error resolving email address: ${err}') } |
| 37 | } |
| 38 | |