Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ananta.mastermind.mail5;
- import android.app.ProgressDialog;
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.IntentFilter;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.support.v7.widget.Toolbar;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Adapter;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.Spinner;
- import android.widget.Toast;
- import java.util.Properties;
- import javax.mail.Authenticator;
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.PasswordAuthentication;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- public class MainActivity extends AppCompatActivity {
- private Toolbar mToolbar;
- Session session = null;
- ProgressDialog pdialog = null;
- Context context = null;
- EditText reciep, sub, msg, ngo, vdc,wrd,village,date,maleA;
- String rec, subject, textMessage, ngoS,district, vdcS,wrdS,villageS,dateS, attendenc,activitYS, ccSupport, vrSupport ,maleAA,femaleA,othersA,maleC,femaleC,otherC,maleV,femaleV,othersC,maleH,femaleH,otherH;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- context = this;
- int num = 0;
- try {
- String value = maleA.getText().trim();
- num = Integer.parseInt( value );
- } catch (NumberFormatException nfe){
- // nothing to do
- }
- mToolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(mToolbar);
- getSupportActionBar().setDisplayShowHomeEnabled(true);
- final Spinner spinner = (Spinner) findViewById(R.id.spinner);
- ArrayAdapter<CharSequence> adapter;
- adapter = ArrayAdapter.createFromResource(this, R.array.activities, android.R.layout.simple_spinner_item);
- adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- spinner.setAdapter(adapter);
- final Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
- ArrayAdapter<CharSequence> adapter2;
- adapter2 = ArrayAdapter.createFromResource(this, R.array.district, android.R.layout.simple_spinner_item);
- adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- spinner2.setAdapter(adapter2);
- Button login = (Button) findViewById(R.id.btn_submit);
- msg = (EditText) findViewById(R.id.et_text);
- ngo = (EditText) findViewById(R.id.editText);
- vdc = (EditText) findViewById(R.id.editText3);
- wrd = (EditText)findViewById(R.id.editText4);
- village = (EditText)findViewById(R.id.editText5);
- date=(EditText)findViewById(R.id.editText6);
- login.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- rec = "anantarajbastola@gmail.com";
- subject = "IFFA FeedBack";
- textMessage = msg.getText().toString();
- ngoS = ngo.getText().toString();
- vdcS = vdc.getText().toString();
- wrdS=wrd.getText().toString();
- villageS=village.getText().toString();
- dateS=date.getText().toString();
- activitYS=spinner.getSelectedItem().toString();
- district=spinner2.getSelectedItem().toString();
- 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.getDefaultInstance(props, new Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication("bastolananta@gmail.com", "coolboy98");
- }
- });
- pdialog = ProgressDialog.show(context, "", "Sending feedback..", true);
- RetreiveFeedTask task = new RetreiveFeedTask();
- task.execute();
- }
- });
- }
- class RetreiveFeedTask extends AsyncTask<String, Void, String> {
- @Override
- protected String doInBackground(String... params) {
- try {
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress("bastolananta4@gmail.com"));
- message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(rec));
- message.setSubject(subject);
- message.setContent(" Name of CW: "+ textMessage +System.getProperty("line.separator") +"Ngo/Cso : " + ngoS +System.getProperty("line.separator")+"District:" + district +System.getProperty("line.separator")+"VDC : " +System.getProperty("line.separator")+ vdcS +"Ward: "+System.getProperty("line.separator")+wrdS+"Village: "+System.getProperty("line.separator")+System.getProperty("line.separator")+villageS+"Date: "+System.getProperty("line.separator")+dateS+ "Activity: " +System.getProperty("line.separator")+activitYS+" Attandence: " +System.getProperty("line.separator")+ attendenc +System.getProperty("line.separator")+ "CC Support: " +System.getProperty("line.separator")+ ccSupport+"VR Suppot: "+System.getProperty("line.separator") + vrSupport+ "Help Desk: ", "text/html; charset=utf-8");
- Transport.send(message);
- } catch (MessagingException e) {
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- @Override
- protected void onPostExecute(String result) {
- pdialog.dismiss();
- Toast.makeText(getApplicationContext(), "Message sent", Toast.LENGTH_LONG).show();
- }
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement