[local-sync, iso-core] feat(send): Support basic sending for gmail accounts

This commit is contained in:
Halla Moore 2016-11-28 14:41:10 -08:00
parent f08e03803c
commit 10f62f6b5a
2 changed files with 29 additions and 9 deletions

View file

@ -79,17 +79,34 @@ module.exports = (sequelize, Sequelize) => {
},
smtpConfig() {
if (this.provider !== "imap") {
throw new Error("Non IMAP not yet supported")
}
const {smtp_username, smtp_password} = this.decryptedCredentials();
const {smtp_host, smtp_port, ssl_required} = this.connectionSettings;
return {
port: smtp_port, host: smtp_host, secure: ssl_required,
auth: { user: smtp_username, pass: smtp_password},
const config = {
host: smtp_host,
port: smtp_port,
secure: ssl_required,
}
if (this.provider === "imap") {
const {smtp_username, smtp_password} = this.decryptedCredentials();
config.auth = { user: smtp_username, pass: smtp_password}
} else if (this.provider === 'gmail') {
const {xoauth2} = this.decryptedCredentials();
const {imap_username} = this.connectionSettings;
// We have to unpack the access token from the entire XOAuth2
// token because it is re-packed during the SMTP connection login.
// https://github.com/nodemailer/smtp-connection/blob/master/lib/smtp-connection.js#L1418
const bearer = "Bearer ";
const decoded = atob(xoauth2);
const tokenIndex = decoded.indexOf(bearer) + bearer.length;
const token = decoded.substring(tokenIndex, decoded.length - 2);
config.auth = { user: imap_username, xoauth2: token }
} else {
throw new Error(`${this.provider} not yet supported`)
}
return config;
},
supportsLabels() {

View file

@ -119,6 +119,9 @@ module.exports = (server) => {
imap_username: email,
imap_host: 'imap.gmail.com',
imap_port: 993,
smtp_username: email,
smtp_host: 'smtp.gmail.com',
smtp_port: 465,
ssl_required: true,
}
connectionCredentials = {