I'm trying to send an email on Sails.JS but I don't know how to do it. I saw a lot of tutorials but none of the tutorials helped me to send an email. I can send an email with the console using curl.
I tried to configure Mailgun but I don't have a Domain. I'm trying to do it free and I'm also very new on Mailgun and Sails.JS. My purpose is to send an email on Sails.JS, but I don't know how.
Follow the steps below to send email from sailsjs using mailgun
Install mailgun module
npm install mailgun-js --save
Create custom variables in config/custom.js file
mailgunDomain: 'yourmailgundomain',
mailgunSecret: 'yourmailgunkey',
mailgunFrom:'yourmailgunfrommail',
Create a helper
sails generate helper send-single-email
var mailgun = require('mailgun-js')({apiKey: sails.config.custom.mailgunSecret, domain: sails.config.custom.mailgunDomain});
module.exports = {
friendlyName: 'Send single email',
description: '',
inputs: {
options:{
type:'json'
}
},
exits: {
},
fn: async function (inputs, exits) {
mailgun.messages().send(inputs.options, function (error, body) {
if(error){
return exits.error(error)
}
// All done.
return exits.success(body);
});
}
};
Call your helper from any controller
await sails.helpers.mail.sendSingleEmail({
to:'destination#email.com',
from:sails.config.custom.mailgunFrom,
subject:'Subject',
text:'Your message'
})
To use Mailgun, you'll need to sign up for an account. (While this is a paid service at higher usage levels, you should be able to use Mailgun as much as you need to in development without having to provide any credit card information.)
After you've created an account, you'll need to add your Mailgun domain and API secret to your custom config. (In development, this will be either in config/custom.js, or in a local.js file you add to your config/ folder. For your staging or production deployment, you'll want to set these using system environment variables -- aka "config variables" in Heroku.)
If you already own a domain for your app, you can follow Mailgun's instructions for configuring a sending domain.
Otherwise, to send emails from this app without configuring a sending domain, you can use the sandbox domain & test API secret that comes with your Mailgun account. Just be sure to configure the authorized recipents for your sandbox domain first, or there will be errors from the endpoints that attempt to send emails.
~~Copied from Sails.js FAQ page when downloading a new app
Related
I'm trying to send an email via smtp.live.com using an OAuth token generated via https://login.microsoftonline.com/common/oauth2/v2.0/… but I'm receiving the following error:
535 5.7.3 Authentication unsuccessful
I can make it work by obtaining an auth token via https://login.live.com/oauth20_authorize.srf (a legacy API) but that only works for free Microsoft accounts (I need to support business/Outlook365 accounts too).
The fact I can make it work using that legacy endpoint seems to validate that:
The server supports XOAUTH2 (which I also validated via Telnet EHLO)
That the encoding is correct (I'm using this process)
That I'm meant to pass the full access token via XOAUTH2 and not something odd like pass it in via LOGIN, or decode the JWT and pass in some component etc.
The access token seems valid (it works for other calls, including sending an email via the Graph API).
I've requested the following scopes:
[
'offline_access', 'User.Read', 'MailboxSettings.ReadWrite',
'Mail.Send', 'Mail.ReadWrite', 'Mail.Read', 'Mail.ReadBasic', 'Contacts.ReadWrite',
'Mail.Read.Shared', 'Mail.ReadWrite.Shared', 'Mail.Send.Shared', 'MailboxSettings.Read',
'profile', 'openid', 'email', 'Calendars.ReadWrite',
'EAS.AccessAsUser.All', 'EWS.AccessAsUser.All',
];
For the legacy token (the one which works), the scopes are different:
[
'wl.emails', 'wl.offline_access', 'wl.imap'
];
(I've tried including these scopes when requesting the v2 token too, but it's invalid).
Other things I've tried:
Using smtp.office365.com instead of smtp.live.com
Obtaining fresh access tokens
Ensuring app settings/permissions are configured correctly, as per this article
Enable Exchange SMTP Auth
Office 365 SMTP servers do not support OAuth authentication as of this time.
Office 365 SMTP servers is supporting OAuth authentication only through Code Authorization Flow not with the other mechanisms like Client Credentials flow e.t.c
I just tried to create a form and associate workflow 'Email notification'.Do i need to specify email address for this workflow?
You need to enable the mail configuration in the forms-flow-bpm (Camunda) and add appropriate mail server and email settings. And deploy it again to get the email sending part working. Please check the readme link here to know more details.
https://github.com/AOT-Technologies/forms-flow-ai/tree/master/forms-flow-bpm#mail-configuration
I am trying to email EML files via Gmail SMTP server using MailKit. I followed example provided by jstedfast to build MimeMesage and send via Gmail SMTP server. I am able to send email using both the simple authentication using (user account, user password) and using OAUTH2. I followed example how to Setting up OAuth2 for use with Google Mail and all works fine, except that it seems that I have to configure access Scopes to include "https://mail.google.com/"
var accessScopes = new[]
{
"https://mail.google.com/",
"https://www.googleapis.com/auth/gmail.send"
};
otherwise sending fails with the following error:
535: 5.7.8 Username and Password not accepted. Learn more at
5.7.8 https://support.google.com/mail/?p=BadCredentials c5sm231676iod.25 - gsmtp
I assumed that I need to configure access scope with the gmail.send only but it doesn't seem to work.
"https://www.googleapis.com/auth/gmail.send"
I don't want to configure "https://mail.google.com/" which implies full access to the gmail account. When the consent screen is presented to users, users may hesitate to accept all access scopes which seems to be required otherwise sending of mails fails.
I tried to configure some of the read only scopes instead of "https://mail.google.com/" but it doesn't seem to work.
What I am missing?
Thank you
The "https://mail.google.com/" scope is the only scope that works with SMTP, POP3 and/or IMAP.
All of the other scopes are only available to use with the Google REST APIs.
I have setup an API Connect developer portal in the sandbox catalog (I've been following the basic tutorials about configuring an API developer portal found here).
I receive a message saying that i'll get a one time login link so that i can login to the portal as admin and reset my password. However, this never arrives. I have tried configuring the portal a number of times now and this link never comes. Therefore i'm unable to login as admin.
I've also tried using the 'request new password' option on the developer portal itself and entering my email but this also does not work
Is there a way I can retrieve the login link?
This could be a number of things:
1) the IBM emails often get flagged as spam
2) the IBM email server, or rather the people they've contracted this out to, doesn't fully comply with DKIM/SPF security, so if you are on a corporate server that requires this then you won't get your emails.
The workaround I've done in the past is spin up a gmail account and be sure to check my spam folder.
I'm sending mail from Jenkins to an anonymous SMTP relay internally. That relay then securely sends mail to exchange online via TLS on port 587. The transport works perfectly, the issue is that Microsoft requires the Sender address match the authentication credentials login name which is the same as the account email address. For example sake, say this is foo#mycompany.com. How can I make jenkins always send mail from foo#mycompany.com?
BTW when I say the transport works perfectly what I mean specifically is that I can drop a formatted e-mail file into the "Pickup" directory on the SMTP relay server and it is properly sent to any recipient provided the From address is foo#mycompany.com.
Jenkins uses the System Admin e-mail address as the sender address for e-mail notification. You can configure this under Manage Jenkins -> Configure System. This is under the Jenkins Location header on that page! It is not immediately obvious that this setting is tied to the e-mail notification settings, since it is not under the E-mail notification header on the configuration page.
Manage Jenkins -> Configure System -> Jenkins Location -> System Admin e-mail address
You can search the page for "Jenkins Location" to change the default value of address not configured yet to whatever you want.
There are two places to add the "E-Mail Notificaitons"
Global level
Local level (Jenkins job level)
To set the E-Mail Notification at Global Level, follow below steps -
1) Go to Manage Jenkins
2) Configure System
3) Jenkins Location
4) System Admin e-mail address
To set the E-Mail Notification at local level (per Jenkins job level), follow below steps -
1) Click on the Job name (if existing one)
2) click on the "Configure"
3) Then look for the "Post-build Action"
4) Specify the email address under "E-mail Notification".
5) Save the changes.
I'm not sure if it is what you meant, but Jenkins enables you to provide a full Sender E-mail Address for notifications. Go to Manage jenkins, then System configuration and find section called E-mail Notification.
You can provide you email address in a form of Jenkins <foo#mycompany.com>.
If you need to do this without using the jenkins UI (for instance in automating a jenkins setup) - you can do so with a groovy script.
import jenkins.model.*
def jenkinsLocationConfiguration = JenkinsLocationConfiguration.get()
jenkinsLocationConfiguration.setAdminAddress("[your admin name] <[your admin email address]>")
// example format -> .setAdminAddress("Jane Doe <foo#company_email.com>")
jenkinsLocationConfiguration.save()
Do note: I did not write this script (although I have tested it and it works), all credit to Peter Halliday and his website with other helpful groovy scripts here.
import javax.mail.Message.RecipientType
import javax.mail.Address
import javax.mail.internet.InternetAddress
import javax.mail.internet.MimeMessage
msg.setFrom(new InternetAddress("john...#server.com"))