Android 如何发送正文包含表单详细信息的电子邮件?
我正在开发基于表单的应用程序。该表单包含客户详细信息。当他单击submit按钮时,表单的详细信息将包含在电子邮件正文中 下面是我的代码: Orders.javaAndroid 如何发送正文包含表单详细信息的电子邮件?,android,email,Android,Email,我正在开发基于表单的应用程序。该表单包含客户详细信息。当他单击submit按钮时,表单的详细信息将包含在电子邮件正文中 下面是我的代码: Orders.java import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import andr
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Order extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.order);
final EditText name = (EditText)findViewById(R.id.username);
final EditText mail = (EditText)findViewById(R.id.email);
final EditText phone = (EditText)findViewById(R.id.phone);
final EditText product = (EditText)findViewById(R.id.product);
final String _name = name.getText().toString();
final String _mail = mail.getText().toString();
final String _phone = phone.getText().toString();
final String _product = product.getText().toString();
System.out.println(_name);
System.out.println(_mail);
System.out.println(_phone);
System.out.println(_product);
Button email = (Button) findViewById(R.id.Button01);
email.setOnClickListener(new OnClickListener(){
public void onClick(View v){
String[] recipients = new String[]{"b.gadwantikar1@gmail.com", "",};
StringBuilder body = new StringBuilder();
StringBuilder body1 = new StringBuilder();
body1.append("To: " + recipients);
body.append("Name: "+name.getText().toString());
body.append("\n\n\nMail: "+mail.getText().toString());
body.append("\n\n\nPhone: "+phone.getText().toString());
body.append("\n\n\nProduct: "+product.getText().toString());
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_EMAIL, body1.toString());
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Customer Details");
i.putExtra(android.content.Intent.EXTRA_TEXT, body.toString());
startActivity(i);
}
});
}
}
xml文件是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:layout_width="60dip"
android:layout_height="wrap_content"
android:id="@+id/edit"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn"
android:text="Click"/>
</LinearLayout>
我正在获取程序中“发件人:”字段中提供的邮件id,但我希望在“收件人:”字段中提供该id…您必须使用
StringBuilder
来管理字符串。邮件应该是html格式的,所以您必须使用html支持的类的方法,比如html.fromHtml(sb.toString())代码>
我只是显示一些文本,这些文本将附加到字符串并发送到邮件正文区域,您可以将表单发送到那个里
public StringBuilder sb;
sb= new StringBuilder();
// This is Mail Format That will be show in Body area and send to be customer.
sb.append("<p><b><font color=\"#8CC248\">Title</b></p>");
sb.append("<p><b><font color=\"#000000\">Dear,"+ edittextvalue in string mode +",</b></p>");
查看您的输出。详细信息应邮寄给管理员……您有什么问题?发送电子邮件或获取正文中的详细信息?获取正文中的详细信息…以下是使用java mail API执行此操作的有用信息[单击此处]()
StringBuilder body = new StringBuilder();
body.append("Name: "+nameField.getText().toString());
body.append("\nAge: "+ageField.getText().toString());
body.append("\nGender: "+genderField.getText().toString());
// Sending to admin
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL, new String[] {"admin@gmail.com"} );
i.putExtra(Intent.EXTRA_SUBJECT, "Customer Details");
i.putExtra(Intent.EXTRA_TEXT, body.toString());
startActivity(i);
StringBuilder body = new StringBuilder();
body.append("Name: "+nameField.getText().toString());
body.append("\nAge: "+ageField.getText().toString());
body.append("\nGender: "+genderField.getText().toString());
// Sending to admin
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL, new String[] {"admin@gmail.com"} );
i.putExtra(Intent.EXTRA_SUBJECT, "Customer Details");
i.putExtra(Intent.EXTRA_TEXT, body.toString());
startActivity(i);