操作\u发送工作正常…android sendmail函数中的javamailapi不工作
我已经开发了一个发送电子邮件的android应用程序 在这里我要发送一个以上的产品详细信息是发送到电子邮件 我使用了以下代码:操作\u发送工作正常…android sendmail函数中的javamailapi不工作,java,android,jakarta-mail,sendmail,Java,Android,Jakarta Mail,Sendmail,我已经开发了一个发送电子邮件的android应用程序 在这里我要发送一个以上的产品详细信息是发送到电子邮件 我使用了以下代码: public class InvoiceOrder extends Activity { String mGrandTotal; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub
public class InvoiceOrder extends Activity {
String mGrandTotal;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.invoice);
Bundle b = getIntent().getExtras();
//String s= getIntent().getStringExtra("orderid");
mGrandTotal = b.getString("GrandTotal");
ListView mLstView1 = (ListView) findViewById(R.id.listView1);
CustomerAdapter mViewCartAdpt = new CustomerAdapter(
InvoiceOrder.this);
mLstView1.setAdapter(mViewCartAdpt);
Button login = (Button) findViewById(R.id.mBtnSubmit);
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("krishnaveniv96@gmail.com","arirajaguru");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("krishnaveni.veeman@mercuryminds.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("mercy.krishnaveni@gmail.com"));
message.setSubject("Testing Subject");
message.setSentDate(new Date());
StringBuilder body = new StringBuilder();
body.append("<html><body><table>");
for (int i = 0; i < Constants.mItem_Detail
.size(); i++) {
String title = Constants.mItem_Detail
.get(i).get(
SingleMenuItem.KEY_PNAME);
String qty = Constants.mItem_Detail.get(i)
.get(SingleMenuItem.KEY_QTY);
String cost = Constants.mItem_Detail.get(i)
.get(SingleMenuItem.KEY_PRICE);
String total = Constants.mItem_Detail
.get(i).get(
SingleMenuItem.KEY_TOTAL);
body.append("<tr>" + "<td>" + title
+ "</td><td>" + qty + " * " + cost
+ "</td>" + " = <td>" + total
+ " " + "</td></tr>");
}
body.append("<tr>" + "<td>" + "Grand Total is:- "
+ "</td><td>" + mGrandTotal + " "
+ "</td></tr>");
body.append("</table></body></html>");
final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent
.putExtra(
Intent.EXTRA_EMAIL,
new String[] { "mercy.krishnaveni@gmail.com,krishnaveni.veeman@mercuryminds.com" });
emailIntent.putExtra(
android.content.Intent.EXTRA_TEXT,
Html.fromHtml(body.toString()));
startActivity(Intent.createChooser(emailIntent,
"Email:"));
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
});
}
}
公共类InvoiceOrder扩展活动{
字符串mGrandTotal;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.invoice);
Bundle b=getIntent().getExtras();
//字符串s=getIntent().getStringExtra(“orderid”);
mGrandTotal=b.getString(“GrandTotal”);
ListView mLstView1=(ListView)findViewById(R.id.listView1);
CustomerAdapter mViewCartAdpt=新CustomerAdapter(
发票订单;
mLstView1.setAdapter(mViewCartAdpt);
按钮登录=(按钮)findviewbyd(R.id.mBtnSubmit);
login.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图arg0){
Properties props=新属性();
put(“mail.smtp.host”、“smtp.gmail.com”);
props.put(“mail.smtp.socketFactory.port”,“465”);
props.put(“mail.smtp.socketFactory.class”,
“javax.net.ssl.SSLSocketFactory”);
props.put(“mail.smtp.auth”,“true”);
props.put(“mail.smtp.port”,“465”);
Session Session=Session.getDefaultInstance(props,
新的javax.mail.Authenticator(){
受保护的密码身份验证getPasswordAuthentication(){
返回新密码身份验证(“krishnaveniv96@gmail.com“arirajaguru”);
}
});
试一试{
Message Message=新的mimessage(会话);
message.setFrom(新的Internet地址(“krishnaveni。veeman@mercuryminds.com"));
message.setRecipients(message.RecipientType.TO,
InternetAddress.parse(“mercy”。krishnaveni@gmail.com"));
message.setSubject(“测试主体”);
message.setSentDate(新日期());
StringBuilder主体=新的StringBuilder();
正文.附加(“”);
对于(int i=0;i
在这里,使用android应用程序中的ACTION_send成功地将多个产品发送到电子邮件
但我必须使用java mail api将不止一个产品细节发送到电子邮件
我使用javamail api意味着单个产品的详细信息只发送给邮件…但我必须发送多个产品的详细信息
这是我的代码:
Multipart multipart = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();
for (int i = 0; i < Constants.mItem_Detail
.size(); i++) {
String title = Constants.mItem_Detail
.get(i).get(
SingleMenuItem.KEY_PNAME);
String qty = Constants.mItem_Detail.get(i)
.get(SingleMenuItem.KEY_QTY);
String cost = Constants.mItem_Detail.get(i)
.get(SingleMenuItem.KEY_PRICE);
String total = Constants.mItem_Detail
.get(i).get(
SingleMenuItem.KEY_TOTAL);
messageBodyPart.setText(title + qty + cost + total);
}
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport.send(message);
Multipart Multipart=new MimeMultipart();
BodyPart messageBodyPart=新的MimeBodyPart();
对于(int i=0;i
我的代码有什么问题。请帮助我。我在使用stringbuffer和append后得到了输出
StringBuffer sb = new StringBuffer();
sb.append("<html><body><table>");
StringBuffer sb=new StringBuffer();
某人加上(“”);
在for循环中:
StringBuffer buffer = sb.append("<tr>" + "<td>" + title
+ "</td><td>" + qty + " * " + cost
+ "</td>" + " = <td>" + total
+ " " + "</td></tr>");
messageBodyPart.setDataHandler(new DataHandler( new ByteArrayDataSource(buffer.toString(), "text/html; charset=utf-8")));
StringBuffer buffer=sb.append(“+”+标题
+“”+数量+“*”+成本
+“+”=“+总计
+ " " + "");
messageBodyPart.setDataHandler(新数据