小编Con*_*ser的帖子

如何直接发送带附件的电子邮件而无需访问外部应用程序

我有这个简单的代码与另一个jar库,使我能够发送电子邮件,而无需去其他邮件应用程序.

 public class claimrewardemail extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.successful);

    final String username = "myname@gmail.com"; 
    final String password = "mypassword"; 



    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Properties props = new Properties();
                props.put("mail.smtp.auth", "true");
                props.put("mail.smtp.starttls.enable", "true");
                props.put("mail.smtp.host", "smtp.gmail.com");
                props.put("mail.smtp.port", "587");

                Session session = Session.getInstance(props,
                        new javax.mail.Authenticator() {
                            protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
                                return new javax.mail.PasswordAuthentication(
                                        username, password);
                            }
                        });
                // TODO Auto-generated method stub
                Message message = new MimeMessage(session);
                message.setFrom(new InternetAddress("from-email@gmail.com"));
                message.setRecipients(Message.RecipientType.TO, …
Run Code Online (Sandbox Code Playgroud)

email android email-attachments

1
推荐指数
1
解决办法
5208
查看次数

标签 统计

android ×1

email ×1

email-attachments ×1