2013-01-04 20 views
1

我必須開發一個android應用程序。 在這裏我必須從我的Android應用程序發送郵件。從我的android應用程序發送郵件

我必須從我的android應用程序發送郵件列表視圖vlaues。

這是我的Android代碼:顯示在這些activity.how

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[]{"[email protected]"}); 
      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中我可以發送列表視圖值email.please給我的解決方案。

編輯:

您好我有發送郵件自動。所以我用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("[email protected]","fg565jhjjh"); 
         } 
        }); 

       try { 

        Message message = new MimeMessage(session); 
        message.setFrom(new InternetAddress("[email protected]")); 
        message.setRecipients(Message.RecipientType.TO, 
          InternetAddress.parse("[email protected]")); 
        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); 
       } 
       } 



     }); 

現在我要automaically列表視圖發送電子郵件。如何我可以設置內容here.please給我的想法。

+0

您想向用戶展示撰寫窗口,還是想自動從您擁有的帳戶發送電子郵件? – SLaks

+0

@ SLaks會自動從我的帳戶發送電子郵件。 – android

+0

您可以爲每個人提供您的電子郵件密碼或設置網絡服務。 – SLaks

回答

2

您需要有一個可接收網絡命令(可能爲REST)的Web應用程序,該應用程序將接收來自應用程序的請求併發送電子郵件。

舉例來說,如果你的服務器位於example.com,那麼你可以有一個URL發送郵件像下面這樣的服務:

example.com/sendmail/和您的POST變量將包含以下變量: 主題,fromAddress,toAddress,內容等

如果您可以使用PHP,Ruby,Python甚至Java等基於網絡的語言進行編程,那麼您可以編寫該代碼,然後從您的應用發送請求。下面的代碼

+0

請看我編輯的問題,並給我這些解決方案。 – android

0

使用發送電子郵件

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
     emailIntent.setType("plain/text"); 
     emailIntent.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"}); 
     emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject"); 
     emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "body text"); 
     startActivity(emailIntent); 
+0

請看我編輯的問題,並給我解決這些 – android

0

嘗試設置要作爲電子郵件發送的「message.setContent(」功能。這將被添加到郵件正文中的數據。(迭代通過列表視圖並將數據添加到字符串變量,然後才被添加到電子郵件消息中)是您要的?

+0

這裏的列表視圖值顯示如下圖所示:https://docs.google.com/file/d/0B8m46AKj3sKwNi1GSHQwcTNQalk/edit如何將該列表視圖值發送到我的電子郵件。 – android

0

要從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: 發送電子郵件直接向一些電子郵件ID通過輸入靜態的Gmail ID和密碼 按照以下網址:
http://davanum.wordpress.com/2007/12/22/android-send-email-via-gmail-actually-via-smtp/
或者可以通過給你的電子郵件ID詢問碼在這裏,並且會向您發送我爲直接發送電子郵件而完成的代碼。

相關問題