Java 从我的android应用程序发送邮件
我必须开发一个android应用程序。 在这里,我必须从我的android应用程序发送邮件 我必须从我的android应用程序发送邮件列表视图 这是我的android代码:Java 从我的android应用程序发送邮件,java,android,android-listview,sendmail,Java,Android,Android Listview,Sendmail,我必须开发一个android应用程序。 在这里,我必须从我的android应用程序发送邮件 我必须从我的android应用程序发送邮件列表视图 这是我的android代码: public class InvoiceOrder extends Activity { String mGrandTotal,mTitle,total,mCost; @Override protected void onCreate(Bundle savedInstanceState) { // TODO A
public class InvoiceOrder extends Activity {
String mGrandTotal,mTitle,total,mCost;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.invoice);
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) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"demo@mercuryminds.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Testing");
i.putExtra(Intent.EXTRA_TEXT , "mLstView1");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(InvoiceOrder.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
});
}
listview显示在这些活动上。我如何将listview值发送到电子邮件。请提供解决方案
编辑:
嗨,我已经自动发送邮件了,所以我使用了javamailapi
现在我更改了代码,如下所示:
public class InvoiceOrder extends Activity {
String mGrandTotal,mTitle,total,mCost;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.invoice);
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("mroslinmhary@gmail.com","fg565jhjjh");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("krishnaveni.veeman@mercuryminds.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("demo@mercuryminds.com"));
message.setSubject("Testing Subject");
message.setContent("This is your product name : "+
"Hi Krishna" +"<br></br>This is your price : "+ "Hi veni", "text/html; charset=utf-8");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
});
公共类InvoiceOrder扩展活动{
字符串mGrandTotal、mTitle、total、mCost;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.invoice);
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(){
返回新密码身份验证(“mroslinmhary@gmail.com“,“FG565JHJH”);
}
});
试一试{
Message Message=新的mimessage(会话);
message.setFrom(新的Internet地址(“krishnaveni。veeman@mercuryminds.com"));
message.setRecipients(message.RecipientType.TO,
InternetAddress.parse(“demo@mercuryminds.com"));
message.setSubject(“测试主体”);
message.setContent(“这是您的产品名称:”+
“嗨,奎师那”+“
这是你的价格:“+”嗨,维尼”,“text/html;charset=utf-8”);
传输。发送(消息);
系统输出打印项次(“完成”);
}捕获(消息异常e){
抛出新的运行时异常(e);
}
}
});
现在,我必须自动将listview发送到电子邮件。我如何在此处设置内容。请告诉我一些想法。您需要一个web应用程序,该应用程序可以接收web命令(可能是REST),该命令将从您的应用程序接收请求并发送电子邮件 例如,如果您的服务器位于example.com,则您可以使用如下URL发送邮件的服务: example.com/sendmail/和您的POST变量将包含以下变量: 主题、fromAddress、toAddress、内容等
如果您可以使用基于web的语言(如PHP、Ruby、Python甚至Java)进行编程,那么您可以编写此代码,然后从应用程序发送请求。使用以下代码发送电子邮件
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(Intent.EXTRA_EMAIL , new String[]{"demo@mercuryminds.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "body text");
startActivity(emailIntent);
尝试在“message.setContent(”函数中设置要作为电子邮件发送的数据。这将被添加到电子邮件正文中。(在添加到电子邮件之前,迭代列表视图并将数据放入字符串变量中)这就是你想要的吗?要从android向用户发送电子邮件,用户有两种方式可以做到这一点。
方法1:
使用意图。代码如下所示:
send = (Button) findViewById(R.id.emailsendbutton);
address = (EditText) findViewById(R.id.emailaddress);
subject = (EditText) findViewById(R.id.emailsubject);
emailtext = (EditText) findViewById(R.id.emailtext);
send.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
try {
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/png");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { address.getText().toString() });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());
//emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText());
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+ getPackageName() + "/" + R.drawable.ic_launcher));
Sendingmail2.this.startActivity(Intent.createChooser(emailIntent,"Send mail..."));
}
catch (Exception e) {
Log.e("", "sendPlainTextEmail() failed to start activity.", e);
//Toast.makeText(this, "No handler", Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(),"No handler", Toast.LENGTH_LONG).show();
}
}
});
方法2: 通过输入静态gmail id和密码直接向某个电子邮件id发送电子邮件 遵循以下URL:
或者,您可以通过在此处提供您的电子邮件id来请求代码,并将我直接发送电子邮件的代码发送给您。您想向用户显示一个撰写窗口,还是想从您拥有的帐户自动发送电子邮件?@SLaks自动从我的帐户发送电子邮件。您可以向每个人提供您的电子邮件密码或设置密码启动web服务。您应该更改您的Gmail密码。请查看我编辑的问题并为我提供解决方案。此处显示的listview值如下图所示:如何将listview值发送到我的电子邮件。