Skip to content

Commit

Permalink
smtp-v add sample code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nedim authored and spytheman committed Jul 18, 2020
1 parent de0fc53 commit 104b1af
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions examples/smtp/mail.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
*
* Creator: nedimf (07/2020)
*/
import os
import net.smtp

fn main() {
println('Hi, this is sample of how to send email trough net.smtp libaray in V.')
println('This should be really easy.\nWe are going to create simple email client that takes some arguments. In this test we are going to send email as HTML body.')
println('To fully test email sending I suggest using mailtrap service which is free and it actually acts like really nice sandbox.')
println('\nEmail client V\n')
mailserver := os.input('Enter your mailserver: ')
from := os.input('From: ')
println('Login')
username := os.input('Enter your username: ')
password := os.input('Enter your password: ')
to := os.input('To: ')
subject := os.input('Subject: ')
body := os.input('Body: ')
client_cfg := smtp.Client{
server: mailserver
from: from
port: 2525
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 |
from: from
}) or {
panic('Error resolving email address')
}
}

0 comments on commit 104b1af

Please sign in to comment.