It looks like the email package in Meteor now allows adding attachments similar to how MailComposer does. On my server I have:
Meteor.startup( function() {
process.env.MAIL_URL = "smtp://<my maligun info here>";
});
Meteor.methods({
sendEmail: function (to, from, subject, text, attachment) {
// Let other method calls from the same client start running,
// without waiting for the email sending to complete.
this.unblock();
Email.send({
to: to,
from: from,
subject: subject,
text: text,
attachment: attachment
});
}
});
Inside the app I'll have a helper like:
Template.donateEmail.events({
'click #send-donate-email': function() {
var attachment = {
fileName: "Demographics3.numbers",
filePath: "/Users/Opal/Desktop/Demographics3.numbers"
};
var emailCompose = document.getElementById('compose-donate-email').value;
var emailSubject = document.getElementById('subject-donate-email').value;
Meteor.call('sendEmail',
"some#email.com", //Session.get('keyDonateEmailSendList'),
'some2#email.com',
emailSubject,
emailCompose,
attachment)
}
});
I can get emails to send, but sending but there's no attachments. And the documentation is confusing. Anyone have any more info on this? I'm missing something somewhere.
Problem solved. Two mistakes in my code. In the Email.send method, it needs to read
"attachments: <some name>" not "attachment: <some name>".
The second issue is the making sure one specifies the correct absolute path, which in my case on a Mac would be:
"Volumes/Macintosh\ HD/Users/Opal/Desktop/<filename>"
I have found that Apple .numbers files aren't openable, but they will attach. Other files should be OK.
Related
I'm trying to send attachment file from youtrack to another system (in this example to trello) without the use of image url but its content
I cannot send it as image url in youtrack because my system is closed and accessible to only those that have vpn.
Problem is with reading inputStream from content of attachement in workflow. I symply have no idea how to do it and youtrack documentation havent touched it (as far as my research goes)
Code: (with truncated not important parts)
//...
exports.rule = entities.Issue.onChange({
//...
action: function(ctx) {
//...
var link = '/1/cards/' + issue['trelloIssueId'] + '/attachments';
issue.comments.added.forEach(function(comment) {
comment.attachments.forEach(function(attachment) {
var response = connection.postSync(link, {
name: attachment.name,
file: attachment.content,
mimeType: attachment.mimeType
});
//...
});
});
},
requirements: {}
});
from this I got error:
TypeError: invokeMember (forEach) on jetbrains.youtrack.workflow.sandbox.InputStreamWrapper#677a561f failed due to: Unknown identifier: forEach
How do I have to prepare content to ba abble to send it with postSync method?
It looks like you tried to iterate over issue.comments.added while the loop should be executed over issue.comments as there is no added key for an issue's comments Set as per the following documentation page suggest: https://www.jetbrains.com/help/youtrack/devportal/v1-Issue.html
Please let me know if that works.
I am using Accounts.emailTemplates.enrollAccount.html.
I can send e-mail successfully using this code:
Accounts.emailTemplates.enrollAccount.html = function(user, url) {
return '<h1>Thank you </h1><br/>Verify eMail';
};
But what I want to do is, I have one external file called email.html and I want to send that file as an e-mail.
My code
Accounts.emailTemplates.enrollAccount.html = function(user, url) {
// i want to send email.html file from here or if you have other way
};
Thank You.
You can use the meteor package meteorhacks:ssr like that :
Accounts.emailTemplates.enrollAccount.html = function(user, url) {
SSR.compileTemplate('htmlEmailVerify', Assets.getText('email.html'));
return SSR.render('htmlEmailVerify', {user: user, url: url});
};
And you can get the data inside the email html code with spacebars tags :
{{user}} & {{url}}
I am trying to construct an email for some users. Code is running server-side. In the email I would like to have a link for the users to click on, but I am not having much luck.
I am trying to use Router.url() to set the href of an anchor. I can do console.log() and see the Router object is at least defined, but the link ends up being strange.
The code looks like this:
Meteor.methods({
sendSubmissionEmail: function(responseId) {
// Let other method calls from the same client start running,
// without waiting for the email sending to complete.
this.unblock();
var formResponse = FormResponses.findOne({_id: responseId});
var toEmails = [];
_.each(Roles.getUsersInRole('ADMIN').fetch(), function(user) {
if (user.profile && user.profile.receivesResponseEmails) {
var email = _.findWhere(user.emails, {verified: true});
if (!email) {
console.log('No verified email address was found for ' + user.username + '. Using unverified email instead.');
email = _.first(user.emails);
}
if (email) {
toEmails.push(email.address);
}
}
});
if (toEmails && toEmails.length > 0) {
console.log('Sending an email to the following Admins: ' + toEmails);
console.log('Router: ', Router);
Email.send({
from: 'noreply#strataconsulting.us',
to: toEmails,
subject: 'Form Response for Form "' + formResponse.form_title + '" Ready For Approval',
html: '<p>Form Response for Form ' + formResponse.formTitle + ' is now ready for your approval.</p>'
});
}
}
});
And the resulting email:
====== BEGIN MAIL #0 ======
MIME-Version: 1.0
From: noreply#strataconsulting.us
To: testuser4#codechimp.net
Subject: Form Response for Form "undefined" Ready For Approval
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<p>Form Response for Form Test Form One is now ready for your approval.</p>
====== END MAIL #0 ======
First, there is a strange "3D" appearing prior to the first " of the href, then the return or Router.url() is always undefined. Just to make sure the call was right, I simulated it in Chrome's dev tools console by doing the following:
var fr = FormResponses.findOne({_id: '1234567890'});
Router.url('editResponse', fr);
As expected this spits out the full URL path to my editResponse route with the correct ID set. Is Router.url() a client-only call? If so, how do I get the URL to a route server-side? All routes are defined for both client and server.
Here:
var fr = FormResponses.findOne({_id: '1234567890'});
Router.url('editResponse', fr);
You're passing the result of the Find as a parameter. It'll look like
{ _id: ..., otherStuff: ...}
But in your code you're not passing an object, you're just passing a string:
Router.url('editResponse', formResponse.id)
That explains the "undefined".
The 3D is very odd.
I use Meteor v1 to buid un app, and to be able to send a email from my app, I add Email package.
This is my code on the client
Template.Home.events({
'click button': function(event, template){
event.preventDefault();
var depart = template.find('[id=exampleInputEmail1]').value;
var arrive = template.find('[id=exampleInputPassword1]').value;
var email = template.find('[id=exampleInputPassword1m]').value;
var nom = template.find('[id=exampleInputPassword1s]').value;
var telephone = template.find('[id=exampleInputPassword1n]').value;
var element = template.find('[id=exampleInputPassword1j]').value;
Meteor.call('sendEmail', 'nwabdou85#yahoo.fr', email, 'Faites moi un devis rapide svp', 'This is a test of Email.send.');
}
});
And the server one is
Meteor.startup(function() {
var username = "postmaster%40sandboxxxxxxxx.mailgun.org";
var password = "xxxxxxxxxxx";
var server = "smtp.mailgun.org";
var port = "587"
process.env.MAIL_URL = 'smtp://' + encodeURIComponent(username) + ':' + encodeURIComponent(password) + '#' + encodeURIComponent(server) + ':' + port;
});
// In your server code: define a method that the client can call
Meteor.methods({
'sendEmail': function (to, from, subject, text) {
// check([to, from, subject, text], [String]);
this.unblock();
Email.send({
to: to,
from: from,
subject: subject,
text: text
});
}
});
but it does not work !! it throw out this error on consol : Error invoking Method 'sendEmail': Internal server error [500]
Can you even have this issue and hwo do you fixe it ??
I would suggest switching your hosting to Heroku, which is free but more configurable. Try reading my recent article on the subject, should give you some hints: http://joshowens.me/modulus-vs-heroku-vs-digital-ocean/.
If that is a 500 error from mailgun then its something on their side not yours. try accessing your dashboard on mailgun and see if you can get some info from there. I spent abit of time trying to get this right and it was all to do with getting the Mail url correct.
I remember in the bulletproof meteor you should use Meteor.defer function to delay your email sending process. Usually sending email caused response timeout.
Again, this.unblock might not useful in this case. Please try to comment out it if the first way doesn't work.
encodeURIcomponent would convert something from sam#sam.com to sam%40sam.com.
Your username is already URI encoded, so doesn't need to be further encoded. In this case, you are double encoding the username, and hence was probably failing with an authentication error.
I'm attempting to run ntwitter streaming API to track tweets about a certain hashtag, populating the Mongo collection Tweets with each tweet.
I've hooked it up server side like so:
t = new nTwitter({
consumer_key: credentials.consumer_key,
consumer_secret: credentials.consumer_secret,
access_token_key: credentials.access_token_key,
access_token_secret: credentials.access_token_secret
});
Meteor.methods({
trackTweets: function () {
this.unblock; // this doesn't seem to work
console.log('... ... trackTweets');
var _this = this;
t.stream(
'statuses/filter',
{ track: ['#love'] },
function(stream) {
stream.on('data', function(tweet) {
// app/packages/mongo-livedata/collection.js:247
// throw e;
// ^
// O yes I love her like money
// Error: Meteor code must always run within a Fiber
console.log(tweet.text);
Tweets.insert(tweet.text); // this call blocks
});
stream.on('error', function(error, code) {
console.log("My error: " + error + ": " + code);
});
}
);
}
});
The line: Tweets.insert(tweet.text) throws the must run inside its own Fiber error – and I've tried putting the this.unblock statement in several different places.
What should I do here?
you dont call the function unblock, you need to replace your
this.unblock;
with this:
this.unblock();
if that doesn't work i would think it has something to do with the way ntwitter is getting the data, you could try to add this
if (Meteor.isClient) return false;
so that the method doesn't run on the client, but only on the server
I believe the code you are running server-side needs to be contained within a Fiber.
Some similar examples can be found in these answers:
Meteor code must always run within a Fiber” when calling Collection.insert on server
Stream stdout to Meteor website