I am having trouble sending an attachment of email.
Firstly: I am using iText5 to stamp some text to a PDF. The PDF is stored in my assets folder:
AssetManager am = getAssets();
InputStream fs;
FileOutputStream fOut ;
try
{
fs = am.open("RFA2_10_11.pdf");
PdfReader pdfReader = new PdfReader(fs);
Log.d("pdfreader", pdfReader.getFileLength()+" kello");
fOut = openFileOutput("DocStamped.pdf",
MODE_WORLD_READABLE);
PdfStamper stamper = new PdfStamper(pdfReader, fOut);
PdfContentByte canvas = stamper.getOverContent(1);
ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("Stefano Molle"), 250, 710, 0);
ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("4 Saint Pappins Road, Glasnevin, Dublin 11"), 250, 645, 0);
stamper.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (DocumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
So the PDF that is created is stored in the root Files Directory of my application.
I need to send the saved DocStamped.pdf file as an attachment in an email:
String emailTo = "example@example.com";
//lets send the email
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{emailTo});
ArrayList<Uri> uris = new ArrayList<Uri>();
File file = new File(getFilesDir()+"/"+"DocStamped.pdf");
Log.d("file", file.getAbsolutePath());
Uri uri = Uri.fromFile(file);
uris.add(uri);
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
// emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Now this is my code to send the email. but I am having trouble. On the app it says there is an attachment, but when I check my email account within the browser, there is no attachment just the text I write in.
Any ideas guys why the attachment is not sending?