Could not load email provider "nodemailer" (Strapi) - node.js

I'm trying to setup the strapi application with nodemailer.
I've added the nodemailer dependency with yarn add #strapi/provider-email-nodemailer as on the official page described. Afterwards I've added the following configuration to my plugins.js file (I've replaced sensitive informations with XXXXXXXX):
module.exports = ({ env }) => ({
email: {
config: {
provider: 'nodemailer',
providerOptions: {
host: env('SMTP_HOST', 'XXXXXXXX'),
port: env('SMTP_PORT', 587),
auth: {
user: env('SMTP_USERNAME', 'XXXXXXXX'),
pass: env('SMTP_PASSWORD', 'XXXXXXXX'),
},
secure: true
},
settings: {
defaultFrom: 'XXXXXXXX',
defaultReplyTo: 'XXXXXXXX',
},
},
},
});
But when I try to strap Strapi with yarn develop I get the following error message:
C:\Dev\Strapi\Projects\strapi>yarn develop
yarn run v1.22.15
$ strapi develop
Building your admin UI with development configuration ...
Admin UI built successfully
[2021-12-27 23:27:51.485] debug: ⛔️ Server wasn't able to start properly.
[2021-12-27 23:27:51.487] error: Could not load email provider "nodemailer".
Error: Could not load email provider "nodemailer".
at createProvider (C:\Dev\Strapi\Projects\strapi\node_modules\#strapi\plugin-email\server\bootstrap.js:23:11)
at Object.module.exports [as bootstrap] (C:\Dev\Strapi\Projects\strapi\node_modules\#strapi\plugin-email\server\bootstrap.js:31:37)
at Object.bootstrap (C:\Dev\Strapi\Projects\strapi\node_modules\#strapi\strapi\lib\core\domain\module\index.js:40:47)
at Object.bootstrap (C:\Dev\Strapi\Projects\strapi\node_modules\#strapi\strapi\lib\core\registries\modules.js:28:19)
at async Strapi.runLifecyclesFunctions (C:\Dev\Strapi\Projects\strapi\node_modules\#strapi\strapi\lib\Strapi.js:463:5)
at async Strapi.bootstrap (C:\Dev\Strapi\Projects\strapi\node_modules\#strapi\strapi\lib\Strapi.js:401:5)
at async Strapi.load (C:\Dev\Strapi\Projects\strapi\node_modules\#strapi\strapi\lib\Strapi.js:410:5)
at async Strapi.start (C:\Dev\Strapi\Projects\strapi\node_modules\#strapi\strapi\lib\Strapi.js:161:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
What am I doing wrong? The configuration seems so simple so I don't have any idea what's wrong.

You need remove config section:
email: {
provider: 'nodemailer',
providerOptions: {
host: env('SMTP_HOST', 'smtp.xxxxxx.xx'),
port: env('SMTP_PORT', xxx),
secure: true,
auth: {
user: env('SMTP_USERNAME'),
pass: env('SMTP_PASSWORD'),
},
},
settings: {
defaultFrom: env('SMTP_FROM_EMAIL'),
defaultReplyTo: env('SMTP_REPLY_EMAIL'),
},
},
UPD: Sorry, I understood now that I use this package https://www.npmjs.com/package/strapi-provider-email-nodemailer and you used this https://www.npmjs.com/package/#strapi/provider-email-nodemailer

Related

Does Nodemailer SMTP work within azure functions?

I'm trying to run a nodemailer service within an azure function app and it keeps throwing AUTH error. Here's my code below :
require("dotenv").config();
const nodemailer = require("nodemailer");
const getMailIDs = require("./getMailIDs");
module.exports = async function mailSender() {
let transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secure: true,
service: "gmail",
auth: {
user: process.env.EMAIL,
pass: process.env.PASSWORD,
},
});
let mailIDs = await getMailIDs();
for (i = 0; i < mailIDs.length; i++) {
await transporter.sendMail({
from: "abc#gmail.com",
to: `${mailIDs[i]}`,
subject: "Test Mail",
text: {
path: `emailBody.txt`,
},
});
}
};
This is the error thrown :
Error: Missing credentials for "PLAIN"
at SMTPConnection._formatError (C:\Projects\azure\node_modules\nodemailer\lib\smtp-connection\index.js:784:19)
at SMTPConnection.login (C:\Projects\azure\node_modules\nodemailer\lib\smtp-connection\index.js:438:38)
at C:\Projects\azure\node_modules\nodemailer\lib\smtp-transport\index.js:271:32
at SMTPConnection.<anonymous> (C:\Projects\azure\node_modules\nodemailer\lib\smtp-connection\index.js:209:17)
at Object.onceWrapper (events.js:299:28)
at SMTPConnection.emit (events.js:210:5)
at SMTPConnection._actionEHLO (C:\Projects\azure\node_modules\nodemailer\lib\smtp-connection\index.js:1319:14)
at SMTPConnection._processResponse (C:\Projects\azure\node_modules\nodemailer\lib\smtp-connection\index.js:947:20)
at SMTPConnection._onData (C:\Projects\azure\node_modules\nodemailer\lib\smtp-connection\index.js:749:14)
at TLSSocket.SMTPConnection._onSocketData (C:\Projects\azure\node_modules\nodemailer\lib\smtp-connection\index.js:189:44) {
code: 'EAUTH',
command: 'API'
}
It executes when I run this script file alone locally. But throws an error when I call it from index.js file of the azure function app. I'm unsure if using google api/ OAUTH is mandatory for azure function app.
Your error code shared shows that NodeMailers is unable to verify your identity.
code: 'EAUTH', command: 'API'
Issue found:
auth: {
user: process.env.EMAIL,
pass: process.env.PASSWORD,
},
Authentication variables used are environment variable.
This works when running locally because you must have an .env file with these variables hosted on your local server.
Solution:
You need to add all environment variables under as "New Application Settings" under "Application Settings" in "Configuration" (Settings Panel).
Doc reference - https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings?tabs=portal
Add the values as under :
Name - EMAIL , value - <youremail>
Name - PASSORD, value - <password>
This should fix the auth issue.

Strapi CMS, Heroku error: no pg_hba.conf entry for host

Three months ago, I created an Strapi App that has deployed on Heroku, and everything works fine. I used macOS 10.13.6 and node 14.15.4 for the local environment
The configuration of database was created inside a file named database.js which located in rootApp/config/env/production/database.js
The following are everything config inside these file (database.js):
const parse = require('pg-connection-string').parse;
const config = parse(process.env.HEROKU_POSTGRESQL_MAROON_URL);
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client: 'postgres',
host: "ec2-35-169-184-61.compute-1.amazonaws.com",
port: 5432,
database: "d3d9tcukxxx",
username: "mwtwuvkwxxxx",
password: "42f0337xxxxx",
},
options: {
ssl:true,
},
},
},
});
But after 3 months (right now), I checked from heroku logs --tail then these app getting an error and the message was:
error error: no pg_hba.conf entry for host "3.86.36.125", user "mwtwuvkwtrqpir", database "d3d9tcukrk5fgh", SSL off
I used Strapi 3.2.5 , and I was deployed on Heroku Postgres with Plan free (Hobby).
I hope everyone helping me for this questions, and hope helping others for same case.
Thank you
We had the same issue on our Heroku instances and just recently found a fix.
Adding rejectUnauthorized to the database config appears to work.
config/database.js
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client: 'postgres',
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'strapi'),
username: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
schema: env('DATABASE_SCHEMA', 'public'), // Not Required
ssl: {
rejectUnauthorized: env.bool('DATABASE_SSL_SELF', false), // For self-signed certificates
},
},
options: {
ssl: env.bool('DATABASE_SSL', false),
},
},
},
});
I cannot take full credit however, it was this post on the Strapi forum that led me to the answer:
https://forum.strapi.io/t/error-no-pg-hba-conf-entry-for-host-ssl-off/3409
subsequently this link:
https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#database

Sails.js - Ignored attempt to bind route (/) to unknown controller :: home

I'm using Ubuntu 14.04 LTS and I'm trying to install this application that makes use of sails.js
When I try to run it with the command sails lift I get this error
error: Ignored attempt to bind route (/) to unknown controller :: home.
This is my local.js file:
module.exports = {
port: process.env.PORT || 1337,
environment: process.env.NODE_ENV || 'development',
hookTimeout: 50000,
connections: {
'default': 'postgresql',
pgigg: {
adapter: 'sails-postgresql',
host: 'localhost',
port: 5432,
user: 'xtenspg',
password: 'xtenspg',
database: 'xtensdb',
pool: true,
ssl: false,
schema: true
},
},
fileSystemConnections: {
default: 'irodsRest',
irodsRest: {
type: 'irods-rest',
restURL: {
hostname: 'localhost',
port: 8080,
path: '/irods-rest/rest'
},
irodsHome: '/tempZone/home/rods',
repoCollection: 'xtens-repo',
landingCollection: 'landing',
username: 'rods',
password: 'rods'
}
},
defaultOperators: [{
firstName: 'default administrator',
lastName: 'sysadmin',
birthDate: '1970-01-01',
sex: 'N.A.',
email: 'blabla#gmail.com',
login: 'admin',
password: 'admin1982'
}
]
};
I have already installed Node.js and PostgreSQL 9.4. This is my configuration:
$ node -v
v5.0.0
$ sails -v
0.12.3
$ bower -v
1.7.9
$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
Can anyone help me?
Also make sure your file name is ended with controller.
For example
ProductSellerController not only
ProductSeller
I have experienced a similar situation, it occurred when the route was specified in the config/routes.js. But the controller or the method in the controller was not loaded or is missing. Otherwise if your routes for / is
'/': {
view: 'homepage'
}
that is the default one. Check if homepage.ejs file is exist in views folder.
bhapri is correct.
Have a look at xtens-app config/routes.js, where we find this:
'GET /': {controller: 'home'},
Yet there is no HomeController.js in api/controllers/
Simply comment or remove that line.
check the directory of controller and focus over lower and uper case of spell.

res.render doesn't render correctly after 1023 characters

I have a parent Express app, and a Ghost app as a child app, using Ghost as an npm module here.
I routed Ghost to be rendered at http://localhost:9000/blog. All the configuration works fine (Ghost will throw an error if the basic configuration isn't being provided correctly).
Here is my Ghost startup code
ghost({
config: path.join(__dirname, '/config/ghost.config.js')
}).then(function (ghostServer) {
app.use(ghostServer.config.paths.subdir, ghostServer.rootApp);
ghostServer.start(app);
});
here is my Ghost config
// # Ghost Configuration
// Setup your Ghost install for various [environments](http://support.ghost.org/config/#about-environments).
// Ghost runs in `development` mode by default. Full documentation can be found at http://support.ghost.org/config/
var path = require('path'),
config;
config = {
// ### Production
// When running Ghost in the wild, use the production environment.
// Configure your URL and mail settings here
production: {
url: 'http://my-ghost-blog.com',
mail: {},
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost.db')
},
debug: false
},
server: {
host: '127.0.0.1',
port: '2368'
}
},
// ### Development **(default)**
development: {
// The url to use when providing links to the site, E.g. in RSS and email.
// Change this to your Ghost blog's published URL.
url: 'http://localhost:9000/blog/',
// Example mail config
// Visit http://support.ghost.org/mail for instructions
// ```
// mail: {
// transport: 'SMTP',
// options: {
// service: 'Mailgun',
// auth: {
// user: '', // mailgun username
// pass: '' // mailgun password
// }
// }
// },
// ```
// #### Database
// Ghost supports sqlite3 (default), MySQL & PostgreSQL
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '../blog/data/ghost-dev.db')
},
debug: false
},
// #### Server
// Can be host & port (default), or socket
server: {
// Host to be passed to node's `net.Server#listen()`
host: '127.0.0.1',
// Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
port: '9000'
},
// #### Paths
// Specify where your content directory lives
paths: {
contentPath: path.join(__dirname, '../blog/')
}
},
// **Developers only need to edit below here**
// ### Testing
// Used when developing Ghost to run tests and check the health of Ghost
// Uses a different port number
testing: {
url: 'http://127.0.0.1:2369',
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost-test.db')
}
},
server: {
host: '127.0.0.1',
port: '2369'
},
logging: false
},
// ### Testing MySQL
// Used by Travis - Automated testing run through GitHub
'testing-mysql': {
url: 'http://127.0.0.1:2369',
database: {
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'root',
password : '',
database : 'ghost_testing',
charset : 'utf8'
}
},
server: {
host: '127.0.0.1',
port: '2369'
},
logging: false
},
// ### Testing pg
// Used by Travis - Automated testing run through GitHub
'testing-pg': {
url: 'http://127.0.0.1:2369',
database: {
client: 'pg',
connection: {
host : '127.0.0.1',
user : 'postgres',
password : '',
database : 'ghost_testing',
charset : 'utf8'
}
},
server: {
host: '127.0.0.1',
port: '2369'
},
logging: false
}
};
module.exports = config;
So basically, when I go to http://localhost:9000/blog, it isn't being rendered at all. Nothing. I was using Chrome and also testing it using Safari. Also tested those two without JavaScript turned on.
And then I try to do curl http://localhost:9000/blog, and try using a requester app (like Postman) and they returned the correct html string. I also tried to do a curl using the user agent as Chrome and as Safari, it also returns the correct html.
I traced down to ghost node_modules, and the renderer is in ghost > core > server > controllers > frontend > index.js in this line res.render(view, result)
I changed the res.render to be like this
res.render(view, result, function(err, string) {
console.log("ERR", err);
console.log("String", string);
res.send(string);
})
and there is no error, it logs the current string, but it doesn't render anything on the browser.
I tried curl, postman, works, but browser doesn't work.
then I tried to send a hello world string, it works, the browser rendered it.
Then I add the string length one by one, and it turns out, any str.length < 1023 will be able to be rendered by the browser, but once it get past that, it doesn't.
And I tried in my parent Express app, it is able to send string which length is more than 1023, and if I use the ghost module as a standalone, it also able to send string more than 1023.
So something must have happened between those two, but I don't know how to debug this.
Please help

intern.js and Browserstack

Intern.js is a great testrunner but it only appears to work with SauceLabs. My company already uses BrowserStack and are very happy with it. I was wondering if anyone has been able to integrate Intern.js with BrowserStack and if so how?
You should be able to use BrowserStack with the following Intern configuration for Intern 1:
define({
capabilities: {
'browserstack.user': 'your-username',
'browserstack.key': 'your-access-key'
},
webdriver: {
host: 'hub.browserstack.com'
},
useSauceConnect: false
});
or this configuration for Intern 2:
define({
tunnel: 'BrowserStackTunnel',
tunnelOptions: {
username: 'your-username', // or use env var BROWSERSTACK_USERNAME
accessKey: 'your-access-key' // or use env var BROWSERSTACK_ACCESS_KEY
}
});
These settings work for me:
tunnel: 'BrowserStackTunnel',
webdriver: {
username: 'your-useranme',
accessKey: 'your-access-key',
},

Resources