如何数据库文件附加到电子邮件中的android? [英] How to attach database file to an Email in android?
本文介绍了如何数据库文件附加到电子邮件中的android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我想通过附加的数据库外商投资企业发送一封电子邮件,我收到的邮件不附加休耕是我的code。 任何一个可以帮助我..? 尝试{
字符串主机=smtp.gmail.com;
从=字符串ABC @ .COM;
字符串传递=aaaaadd;
属性道具= System.getProperties();
props.put(mail.smtp.starttls.enable,真); //加入这一行
props.put(mail.smtp.host,主持人);
props.put(mail.smtp.user,从);
props.put(mail.smtp.password,通);
props.put(mail.smtp.port,587);
props.put(mail.smtp.auth,真);
的String []为= {to@mail.com}; //加入这一行
会话会话=作为Session.getDefaultInstance(道具,NULL);
的MimeMessage消息=新的MimeMessage(会议);
message.setFrom(新网际(从));
网际[]的toAddress =新的网际[to.length]
//要获得地址的数组
的for(int i = 0; I< to.length;我++){
的toAddress [我] =新的网际(在[I]);
}
的for(int i = 0; I< toAddress.length;我++){
message.addRecipient(Message.RecipientType.TO,的toAddress [I]);
}
message.setSubject(送一组);
message.setText(欢迎来到JavaMail的); //唯一的例外是在这里抛出
FileDataSource FDS =新FileDataSource(新文件(/数据/数据/软件包名/数据库/ dbname.txt));
//fds.getFile();
Log.v(文件名称是,fds.getFile()的toString());
Log.v(文件大小是,fds.getContentType());
message.setDataHandler(新的DataHandler(FDS));
message.setFileName(Callist.db);
message.setDisposition(Part.ATTACHMENT);
交通运输= session.getTransport(SMTP);
transport.connect(主机,从,通);
transport.sendMessage(消息,message.getAllRecipients());
transport.close();
Toast.makeText(getApplicationContext(),E邮件已发送,Toast.LENGTH_SHORT).show();
}
赶上(例外五){
Toast.makeText(getApplicationContext(),..+ e.toString(),Toast.LENGTH_LONG).show();
}
}
解决方案
电子邮件程序不能访问你的应用程序的私有文件,在这种情况下,你要发送的数据库。将数据库复制到文件夹在SD卡,并从那里将其安装。
HI I am trying to send an email by attaching a database fie, i am getting mail without attaching the fallowing is my code. can any one help me..? try{
String host = "smtp.gmail.com";
String from = "abc@.com";
String pass = "aaaaadd";
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable", "true"); // added this line
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
String[] to = {"to@mail.com"}; // added this line
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress[] toAddress = new InternetAddress[to.length];
// To get the array of addresses
for( int i=0; i < to.length; i++ ) {
toAddress[i] = new InternetAddress(to[i]);
}
for( int i=0; i < toAddress.length; i++) {
message.addRecipient(Message.RecipientType.TO, toAddress[i]);
}
message.setSubject("sending in a group");
message.setText("Welcome to JavaMail");//The exception is thrown here
FileDataSource fds = new FileDataSource(new File("/data/data/packagename/databases/dbname.txt"));
//fds.getFile();
Log.v("File name is", fds.getFile().toString());
Log.v("File size is", fds.getContentType());
message.setDataHandler(new DataHandler(fds));
message.setFileName("Callist.db");
message.setDisposition(Part.ATTACHMENT);
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
Toast.makeText(getApplicationContext(), "E mail Sent", Toast.LENGTH_SHORT).show();
}
catch(Exception e){
Toast.makeText(getApplicationContext(), " .."+e.toString(), Toast.LENGTH_LONG).show();
}
}
解决方案
The email program can't access your application's private files, in this case, the database you are trying to send. Copy the database to a folder in the SD card and attach it from there.
这篇关于如何数据库文件附加到电子邮件中的android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文