send mail without user interaction don't work [closed]

HerzZorro

New Member
I have a class "mail" with code for send mail without user interaction taken from this web page, and work...manifest.xlm is:\[code\] <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.alertacumples" android:versionCode="1" android:versionName="1.0" > <uses-permission android:name="android.permission.INTERNET"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".AlertaCumpleActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MensajeConfirmacion" /> <service android:name="SendMailService" /> </application></manifest>\[/code\]When I add uses-sdk to manifest (any api...3,6,8,10) the mail don't send...This is the call to the mail.class....is a service(SendMailService.class):\[code\] Mail m = new Maila(<My mail>, <my pass>); String[] toArr = {<mail to send>}; m.setTo(toArr); m.setFrom("<my mail>"); m.setSubject("sunject examplle"); m.setBody("Email body"); String retorno=""; try { m.addAttachment("/sdcard/traces.txt"); if(m.send()) { retorno="Se ha enviado el email"; } else { retorno="No se ha podido enviar el email"; } } catch(Exception e) { retorno="Ocurrio un problema con el servicio de mails"; }\[/code\]If I delete uses-sdk line to the manifest.xml the program work...if not:\[code\]retorno="Ocurrio un problema con el servicio de mails";\[/code\]Sorry for my bad english.Copied in from asker's comment below:the code add this file to zip and send this zip in mail... \[code\]public void addAttachment(String filename) throws Exception { // Antes de adjuntar el fichero se comprime en zip String outputFilename = filename+".zip"; File outputFile = new File(outputFilename); FileOutputStream fos = new FileOutputStream(outputFile); File inputFile = new File(filename); BufferedInputStream fis = new BufferedInputStream(new FileInputStream(inputFile)); ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos)); try { byte[] buffer = new byte[1024]; ByteArrayOutputStream stream = new ByteArrayOutputStream(); int len1 = 0; while ((len1 = fis.read(buffer)) != -1) { stream.write(buffer, 0, len1); } byte[] bytes = stream.toByteArray(); ZipEntry entry = new ZipEntry(outputFilename); zos.putNextEntry(entry); zos.write(bytes); zos.closeEntry(); } finally { zos.close(); fos.close(); fis.close(); } // Se adjunta el zip BodyPart messageBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource(outputFilename); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(filename); _multipart.addBodyPart(messageBodyPart);} \[/code\]
 
Back
Top