I am trying to use Cordova plugin called Email Composer to let users send emails. Cordova Email Plugin
I am generating some html content and want to prefill body of the email with the content.
The code I have tried:
function emailHtml(text) //variable to fill the body
{
cordova.plugins.email.isAvailable(
function (isAvailable) {
cordova.plugins.email.open({
to: 'your#email',
cc: 'second#mail',
bcc: [],
subject: 'Greetings',
body: text //the HTML content
});
}
);
}
But it does not work yet.
What is the proper way to use variables for the plugins fields?
Thanks.
You can actually do it by plain Javascript , No need to add additional plugin and increase the build size
let Link="mailto:someone#example.com?subject=Hello%20again";
window.open(Link, "_system");
You can add all the parameter you need in the link.
You need to use parameter isHtml: true
myHTML="<html> ......... </html>";
cordova.plugins.email.isAvailable(
function (isAvailable) {
cordova.plugins.email.open({
to: 'your#email',
cc: 'second#mail',
bcc: [],
subject: 'Greetings',
body: myHTML, //the HTML content
isHtml: true // indicats if the body is HTML or plain text
});
}
);
Related
I have the following code:
const input = document.querySelector('input')
btn.addEventListener('click',() => {
Email.send({
Host: 'smtp.gmail.com',
Username:'',
Password:'',
To:input.value,
Subject:"",
From: '',
Body:''
}).then(msg=>console.log(msg))
And in the body I want to send a photo, on the next row text and then a hyperlink(or even the button) Is it possible or smtpjs does not provide that functuonality? Couldn't find anything
Or maybe there is another source(not smtpjs), where I could write a template of the letter and then send it
To send the files, you can define the attachment.
Email.send({
SecureToken : "<your security token>",
To : '<whom you want to send>',
From : "<Your email id registered on SMTPJS>",
Subject: "<Subject>",
Body: "<Body Content>",
Attachments:
[{
name: "File_Name_with_Extension",
path: "Full Path of the file"
}]
})
.then(function (message) {
//
}
Next, if you want to send the hyperlink, I think you can use the html content on body instead of text.
...
Body: "Click <a href='[full_path of link]'>here</a> <button>Button</button>",
...
But the onClick event or other javascript actions will not work for button.
Thank you
I'm using npm pacakge to open mail client with data:
https://www.npmjs.com/package/react-native-mail-compose
Also, I'm using their example:
import MailCompose from 'react-native-mail-compose';
// later in your code...
async sendMail() {
try {
await MailCompose.send({
toRecipients: ['to1#example.com', 'to2#example.com'],
ccRecipients: ['cc1#example.com'],
bccRecipients: ['bcc1#example.com', 'bcc2#example.com'],
subject: 'This is subject',
text: 'This is body',
html: '<p>This is <b>html</b> body</p>', // Or, use this if you want html body. Note that some Android mail clients / devices don't support this properly.
attachments: [{
filename: 'mytext', // [Optional] If not provided, UUID will be generated.
ext: '.txt',
mimeType: 'text/plain',
text: 'Hello my friend', // Use this if the data is in UTF8 text.
data: '...BASE64_ENCODED_STRING...', // Or, use this if the data is not in plain text.
}],
});
} catch (e) {
// e.code may be 'cannotSendMail' || 'cancelled' || 'saved' || 'failed'
}
}
and call this function on button press. All data is OK, except body, for example here in Subject there is "This is subject", in CC of mail clients, there is "cc1#example.com", but body is always empty, I can't ever see "This is body" in mail client.
I've fixed it with another package react-native-send-intent.
It works like a charm! :)
I see, give this package a try.
https://github.com/anarchicknight/react-native-communications
Its very simple to use
I am trying to send html as a body with email composer. html body contains hyperlink but it is not working in gmail. Gmail display plain text only.
var email = {
to: sendersemail+';',
cc: '',
bcc: '',
attachments: [cordova.file.externalApplicationStorageDirectory+'Report.pdf'],
subject: '',
body: '<p>the brain out your I think you'll find it helpful too.</p>',
isHtml: true
};
$cordovaEmailComposer.open(email).then(null, function () {
// user cancelled email
});
use html instead of body!
var email = {
to: sendersemail+';',
cc: '',
bcc: '',
attachments: [cordova.file.externalApplicationStorageDirectory+'Report.pdf'],
subject: '',
html: '<p>the brain out your I think you'll find it helpful too.</p>'
};
$cordovaEmailComposer.open(email).then(null, function () {
// user cancelled email
});
I have the following lines, This is what I tried, and it works fine but I want to load a template for drawing the content inside, how can I attach a file for being displayed as a content of the email? Here comes what I have:
attachment:[{data: req.__({ phrase: 'Please click this link to reset your password: https://website.com/reset/%s', locale: locale}, user.uuid), alternative:true}]
How can I load a path to read the content from something like an HTML file?
I can use a template adding this lines:
var forgotTemplate = fs.readFileSync('../public/mailplates/forgot');
and then:
attachment: [{data: forgotTemplate, alternative:true}]
Anyway, I need to fit the "hash" for change the password, how can i add a script line inside or at least a string?
var email = require("./path/to/emailjs/email");
var server = email.server.connect({
user: "username",
password:"password",
host: "smtp.your-email.com",
ssl: true
});
var message = {
text: "... ",
from: "...",
to: "...",
subject: "testing emailjs",
attachment:
[
{data:"<html>i <i>hope</i> this helps</html>", alternative:true},
{path:"path/to/file.zip", type:"application/zip", name:"renamed.zip"}
]
};
// send the message and get a callback with an error or details of the message that was sent
server.send(message, function(err, message) { console.log(err || message); });
Finally, a solution is with Jade, i add:
var jade = require('jade');
and then:
var forgotTemplate = jade.renderFile('../public/mailplates/forgot.jade', {userRecover: userInfoRecover});
The Jade template must display something like this:
doctype html
html
head
title = forgot password
body
h1 this works
a(href='#{ userRecover }') link
Trying to att. a file using dpd-email (its using nodemailer)
by examples in nodemailer (https://github.com/andris9/Nodemailer#attachments)
This just gives me a file of 'attachment-1.bin' 0kb of size
tried using diffrent post examples from the nodemailer site, but same result.
Using chrome postman
http://localhost:99/email
to:"asa#me.me"
subject: "test"
text: "test"
attachments: [
{filename: "test.tx"', content:"hello world", contentType:"text/plain"}
]
In NodeMailer, attachments is an array of attachment objects. In your above code snippet though, you're setting attachments to an object instead of an array.
Taken directly from E-mail Message Fields
attachments - An array of attachment objects
Change
attachments: {
filename: 'text.bin',
content: 'hello world!',
contentType: 'text/plain'
}
To
attachments: [
{
filename: 'text.bin',
content: 'hello world!',
contentType: 'text/plain'
}
]