Hi,
Can anyone point me to an example of sending email through Gmail?
Thanks!
Hi,
Can anyone point me to an example of sending email through Gmail?
Thanks!
On Sat, 20 Apr 2024 22:24:52 GMT, Rey Valeza wrote:
Hi,
Can anyone point me to an example of sending email through Gmail?
Thanks!
import vibe.vibe;
import vibe.mail.smtp;
import vibe.stream.tls;
class Mailer
{
SMTPClientSettings settings;
this(const string host, const ushort port, const string username, const string password)
{
settings = new SMTPClientSettings(host, port);
settings.connectionType = SMTPConnectionType.startTLS;
settings.authType = SMTPAuthType.plain;
settings.username = username;
settings.password = password;
settings.tlsValidationMode = TLSPeerValidationMode.validCert;
}
~this() {}
public void sendEmail()
{
auto mail = new Mail;
mail.headers["Date"] = Clock.currTime(PosixTimeZone.getTimeZone("Europe/Amsterdam")).toRFC822DateTimeString();
mail.headers["Content-Type"] = "text/plain;charset=utf-8";
mail.headers["From"] = "<noreply@example.com>";
mail.headers["To"] = "some_user@example.com";
mail.headers["Subject"] = "a subject";
mail.bodyText = "Some body text";
sendMail(settings, mail);
}
}