Email composer doesn't find attachment


#1

Hi,

I’m using the following plugin to send an email with a pdf: https://github.com/katzer/cordova-plugin-email-composer

I can send an email, but the attached pdf is never included. The pdf is saved with the file plugin and is then retrieved. After some googling it seems that people have had luck with toNativeUrl method to get the right path.

And if I go:

$scope.filepath =  fileEntry.toNativeURL(); 
window.location.href = $scope.filepath;

The PDF opens up in the browser, so the PDF is obviously created and can be opened, but when I pass the path to the email plugin like so:

$scope.emailer($scope.filepath);	
$scope.emailer = function(filepath) {
	

	alert(filepath);

	
	window.plugin.email.open({
			to:      ['info@appplant.de'],
			subject: 'Congratulations',
			body:    '<h1>Happy Birthday!!!</h1>',
			attachments: [filepath]		
	});

I get the follwing error in the system log:
Attachment path not found: /Users/myname/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/D781404D-5C5A-4458-ABAD-9741355D9060/Documents/test.pdf

All help much appreciated!


#2

Not exactly about pdf, but I wrote a tutorial about including local images as attachments, so you might check it out as it’s almost the same.

You could try:

var name = $scope.filepath.substr($scope.filepath.lastIndexOf('/') + 1);
correctPath = "" + cordova.file.dataDirectory + name;
...
attachments: [correctPath]		

Let me know if it works for you!