mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-06 12:44:30 +08:00
[local-sync, iso-core] feat(send): Support basic sending for gmail accounts
This commit is contained in:
parent
f08e03803c
commit
10f62f6b5a
2 changed files with 29 additions and 9 deletions
|
@ -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() {
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Add table
Reference in a new issue