I have tested my meteor app on dev and the verification email is sent out. But on production it is not. Could it maybe the content of smtp.js? My code is as follows:
// server/smtp.js
Meteor.startup(function () {
var smtp = {
username: 'dummy#wbs.co.za',
password: 'hw783378hjshd',
server: 'smtp.wbs.co.za',
port: 25
}
process.env.MAIL_URL = 'smtp://' + encodeURIComponent(smtp.username) + ':' + encodeURIComponent(smtp.password)
+ '#' + encodeURIComponent(smtp.server) + ':' + smtp.port;
});
// (server-side)
Meteor.startup(function() {
// By default, the email is sent from no-reply#meteor.com. If you wish to receive email from users asking for help with their account, be sure to set this to an email address that you can receive email at.
Accounts.emailTemplates.from = 'NOREPLY <no-reply#meteor.com>';
// The public name of your application. Defaults to the DNS name of the application (eg: awesome.meteor.com).
Accounts.emailTemplates.siteName = 'No Reply';
// A Function that takes a user object and returns a String for the subject line of the email.
Accounts.emailTemplates.verifyEmail.subject = function(user) {
return 'Confirm Your Email Address';
};
// A Function that takes a user object and a url, and returns the body text for the email.
// Note: if you need to return HTML instead, use Accounts.emailTemplates.verifyEmail.html
Accounts.emailTemplates.verifyEmail.html = function(user, url) {
return 'click on the following link to verify your email address: ' + url;
};
});
// (server-side) called whenever a login is attempted
Accounts.validateLoginAttempt(function(attempt){
if (attempt.user && attempt.user.emails && !attempt.user.emails[0].verified ) {
console.log('email not verified');
throw new Meteor.Error(403, 'Verification email has been sent to your email address. Use the url in the email to verify yourself.');
return false; // the login is aborted
}
return true;
});
Please help.
Related
I am new to AppMaker but I have developer experience.
The application is a Project Tracker Application
What I expect to happen: When creating a project the user uses a User Picker to select the users associated with that project. When the project is created I want to email the users associated with that project.
The issue: On clicking the Add button addProject(addButton) client script function is called.
Inside this function sendEmailToAssignees(project, assignees) is called which should reach out to the Server script and run the notifyAboutProjectCreated(project, assignees) but that is not happening.
Things to know: With logging I never reach 'Trying to send email' so I seem to never reach my server script. Also, On client script when I comment out sendEmailToAssignees function everything runs smooth. I have looked at this documentation as a resource so I feel my implementation is okay. https://developers.google.com/appmaker/scripting/client#client_script_examples
The final error message I get is:
Failed due to illegal value in property: a at addProject
(AddProject:110:24) at
AddProject.Container.PanelAddProject.Form1.Spring.ButtonAdd.onClick:1:1
Am I missing something here? Any help would be greatly appreciated. Thank you!
Client Script
function sendEmailToAssignees(project, assignees) {
google.script.run
.withSuccessHandler(function() {
console.log('Sending Email Success');
}).withFailureHandler(function(err) {
console.log('Error Sending Email: ' + JSON.stringify(err));
})
.notifyAboutProjectCreated(project, assignees);
}
function addProject(addButton) {
if (!addButton.root.validate()) {
return;
}
addButton.datasource.createItem(function(record) {
var page = app.pages.AddProject;
var pageWidgets = page.descendants;
var trainees = pageWidgets.AssigneesGrid.datasource.items;
var traineesEmails = trainees.map(function(trainee) {
return trainee.PrimaryEmail;
});
record.Assignee = traineesEmails.toString();
var assignees = traineesEmails.toString();
var project = record;
updateAllProjects(record);
console.log('update all projects done');
sendEmailToAssignees(project, assignees);
console.log('Send Email done');
if (app.currentPage !== app.pages.ViewProject) {
return;
}
gotoViewProjectPageByKey(record._key, true);
});
gotoViewProjectPageByParams();
}
Server Script
function notifyAboutProjectCreated(project, assignees) {
console.log('Trying to send email');
if (!project) {
return;
}
var settings = getAppSettingsRecord_()[0];
if (!settings.EnableEmailNotifications) {
return;
}
var data = {
appUrl: settings.AppUrl,
assignee: project.Assignee,
owner: project.Owner,
startDate: project.StartDate,
endDate: project.EndDate,
jobType: project.Type,
jobId: project.Id
};
// Email Subject
var subjectTemplate = HtmlService.createTemplate(settings.NotificationEmailSubjectJob);
subjectTemplate.data = data;
var subject = subjectTemplate.evaluate().getContent();
// Email Body
var emailTemplate =
HtmlService.createTemplate(settings.NotificationEmailBodyJob);
emailTemplate.data = data;
var htmlBody = emailTemplate.evaluate().getContent();
console.log('About to send email to:', assignees);
sendEmail_(null, assignees, subject, htmlBody);
}
The reason you are getting this error is because you are trying to pass the client "project record" to the server. If you need to access the project, then pass the record key to the server and then access the record on the server using the key.
CLIENT:
function sendEmailToAssignees(project, assignees) {
var projectKey = project._key;
google.script.run
.withSuccessHandler(function() {
console.log('Sending Email Success');
}).withFailureHandler(function(err) {
console.log('Error Sending Email: ' + JSON.stringify(err));
})
.notifyAboutProjectCreated(projectKey , assignees);
}
SERVER:
function notifyAboutProjectCreated(projectKey, assignees) {
console.log('Trying to send email');
var project = app.models.<PROJECTSMODEL>.getRecord(projectKey);
if (!project) {
return;
}
//Rest of the logic
}
The project record object in the client is not the same as the project record object in the server; hence the ilegal property value error.
I'm trying to send a email using form and also save the history of all the email. and I have a field in database named success to track if the email has send or not. How to update values of a field from client script based on user activities or email sent status.
var success = app.models.ChangeSystem.fields.Success.possibleValues;
google.script.run
.withFailureHandler(function(error){
status.text = error.message;
success = False;
})
.withSuccessHandler(function(result){
status.text = 'Email sent';
success = True;
clearEmailForm();
})
.sendEmailMessage(to, subject, msg);
Here success is a field in my database. My script is sending email. and update the
I was expecting to update the value of success which has two possible values(I'm fine if I have to change the field to boolean). Anyone can give me a direction how to achieve that?? Thanks in Advance.
Typically if you are creating a record that has a dependency on an email being sent then you need to implement the email function and call back inside the success function of the record being created like so:
Lets say you have a form with a button that creates a record that has an email sent status field then your 'Submit Button' should have the following code:
var status = app.pages.Email.descendants.EmailStatus;
widget.datasource.createItem({
success: function(result) {
google.script.run
.withFailureHandler(function(e) {
status.text = e.message;
result.Success = false;
})
.withSuccessHandler(function() {
status.text = 'Email sent';
result.Success = true;
})
.sendEmailMessage(to, subject, msg);
},
failure: function(error) {
status.text = error.message;
}
});
I am using meteor for developing my application. I need to verify user as soon as he register himself. I used SendverificationEmail() method of meteor and i m getting link on the server side . Now i want to send that unique link to the client's register email. How it will done?
You will have to use meteor Email package to send email:
Meteor Email Package
After you have added package just write below code in your method to send an email
Email.send({ to, from, subject, text });
Sorry to See this post little late, but there are many folks out there who are willing to implement this even today. So below are the steps to achieve email verification flow.
NOTE: I am using Meteor 1.6.1.1, with Flow-routers + Blaze Templates. Also, make sure you have enabled 3rd party API access call to Gmail. You can do this from Gmail settings.
Import Packages: accounts-ui, accounts-password
In root_folder/server/ folder, inside main.js copy paste below code and make the necessary credential change to your file.
var username = 'asdasdasdas';
var password = 'sdasdasdasd';
var server = 'smtp.gmail.com';
var port = '465';
process.env.MAIL_URL = 'smtps://' +
encodeURIComponent(username) + ':' +
encodeURIComponent(password) + '#' +
encodeURIComponent(server) + ':' + port;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
Accounts.emailTemplates.from = 'support_team#domain.com';
//-- Application name
Accounts.emailTemplates.siteName = 'Your Site Name';
//-- Subject line of the email.
Accounts.emailTemplates.verifyEmail.subject = function(user) {
return 'Email Confirmation.';
};
//-- Email text
Accounts.emailTemplates.verifyEmail.text = function(user, url) {
var newUrl = url.replace('/#','');
return 'Thank you for registering. Please click on the following link to verify your email address: \r\n' + newUrl;
};
// Configure to send the Email Verification mail as true
Accounts.config({
sendVerificationEmail: true,
restrictCreationByEmailDomain: function(email) {
var domain = email.slice(email.lastIndexOf("#")+1); // or regex
var allowed = ["gmail.com", "yahoo.co.in", "outlook.com", "yahoo.com", "yandex.com", "protonmail.com", "protonmail.ch", ];
return _.contains(allowed, domain);
},
loginExpirationInDays: 1
});
When you successfully create an account in Meteor app, you will get an email as below;
Inside the mail, You will see a link with route of pattern /verify-email/:token, hence go inside project/client/routes.js you need to add the route,
import { FlowRouter } from 'meteor/kadira:flow-router';
//force user to stay on home page instead of desired page
Accounts.onLogin(function(user){
var user = Meteor.user();
if(user.emails && user.emails[0].verified){
FlowRouter.go('dashboard');
}
});
FlowRouter.route('/verify-email/:tokenId', {
name: 'verify-email',
action: function(params, queryParams) {
var token = FlowRouter.getParam("tokenId");
console.log(token);
Accounts.verifyEmail(token, function(err){
if(!err){
FlowRouter.go("dashboard");
} else {
FlowRouter.go("error-page");
}
});
},
});
In case if you are using iron-router, you can refer this LINK
I have the running app which sends verification emails in case of email/account name creation but it does not send verification email if I login with google/facebook; it is probably due to email address which is in services.google.email; how can I set field 'to' in Accounts.emailTemplates if it does exist.
configureAccounts = function() {
setMailVerification(enableMailVerification);
};
setMailVerification = function() {
Accounts.emailTemplates.from = 'myEmail#.com';
Accounts.emailTemplates.verifyEmail = {
subject : function(user) {
return "Confirmation"
},
text : function(user, url) {
var greeting = (user.profile && user.profile.nick) ? ("Hello " + user.profile.nick + ",") : "Hello,";
return greeting +
"\n\n" + "Thank you for registration."+
"\n" + "To confirm click the following link:" + url +
"\n\n" + "thank you."
}
};
Accounts.config({
sendVerificationEmail : true,
forbidClientAccountCreation : false
});
};
please let me know if you where I should put ...services.google.email in case of google login and the same for facebook...
in other words how I can sent verification email to Meteor.user().services.google.email .. (even recalling sendUserVerificationEmail with that email does not work as it is not in 'emails')
I modified .email property onCreateUser as follows:
if(user.services != undefined) {
console.log('services in onCreateUser');
user.sentVerificationEmail = false;
user.emails =[];
var emailServices = user.services.google != undefined ?
user.services.google.email :
user.services.facebook.email;
user.emails.push({
address : emailServices,
verified : false
});
}
if (options.profile)
user.profile = options.profile;
return user;
I called then Accounts.sentVerificationEmail then onLogin .. and it worked;
thank you all for having a look
What sets the return URL for the verification email. Not the link that gets generated and inserted in the email, but when you click the link, it ends up going to a page on your site after its verified. How can I set what page it goes to?
You can set the URL by specifying Accounts.emailTemplates.verifyEmail.text. Here's an example:
Accounts.emailTemplates.siteName = 'MyApp';
Accounts.emailTemplates.from = 'me#example.com';
Accounts.emailTemplates.verifyEmail.subject = function() {
return 'Verify your email address on MyApp';
};
Accounts.emailTemplates.verifyEmail.text = function(user, url) {
var token = url.split('/').pop();
var verifyEmailUrl = Meteor.absoluteUrl("verify-email/" + token);
return verifyEmailEmailBody(verifyEmailUrl);
};
The callback takes a url parameter which is the default URL generated by meteor. You can extract the verification token and then use it to build a custom URL. The function needs to return a body string, which you'll generate by implementing verifyEmailEmailBody.
On the client, you'll need to set up the corresponding route. When the route is run, you can call Accounts.verifyEmail.
You can change the verification url used in the email and then handle that route yourself. Here I'll use /verify and redirect to /wherever if successful.
client
var match = window.location.pathname.match(/^\/verify\/(.*)$/);
var token;
if (match) {
token = match[1];
}
Meteor.startup(function () {
if (token) {
Accounts.verifyEmail(token, function (error) {
if (!error) {
window.location.pathname = '/wherever';
}
});
}
});
server
Accounts.urls.verifyEmail = function (token) {
return Meteor.absoluteUrl('verify/' + token);
};