examples: add example for using the SMTP module (#5870)

pull/5874/head
Nedim 2020-07-18 14:59:54 +02:00 committed by GitHub
parent de0fc53d62
commit b3011b4f19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,40 @@
// Creator: nedimf (07/2020)
import os
import net.smtp
fn main() {
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.')
println('We are going to create a simple email client, that takes some arguments. and then sends email with an HTML body.')
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.')
println('')
println('V Email client')
println('')
mailserver := os.input('Mail server: ')
mailport := os.input('Mail server port: ').int()
println('Login')
username := os.input('Username: ')
password := os.input('Password: ')
from := os.input('From: ')
to := os.input('To: ')
subject := os.input('Subject: ')
body := os.input('Body: ')
client_cfg := smtp.Client{
server: mailserver
from: from
port: mailport
username: username
password: password
}
send_cfg := smtp.Mail{
to: to
subject: subject
body_type: .html
body: body
}
mut client := smtp.new_client(client_cfg) or {
panic('Error configuring smtp')
}
client.send(send_cfg) or {
panic('Error resolving email address')
}
}