I have this class for sending email with android
public class SendMailTask extends AsyncTask {
private ProgressDialog statusDialog;
private Activity
From fragment to activity use this :
((YourActivityName)getActivity()).yourPublicMethod();
From activity to fragment use this :
FragmentManager fragmentManager = getSupportFragmentManager();
//include fragment via layout xml
YourFragmentClass fragment = (YourFragmentClass)fragmentManager.findFragmentById(R.id.your_fragment_id);
fragment.yourPublicMethod();
Change below code
new SendMailTask(MainActivity.this).execute(fromEmail,
fromPassword, toEmailList, emailSubject, emailBody);
To
new SendMailTask(getActivity()).execute(fromEmail,
fromPassword, toEmailList, emailSubject, emailBody);
For more details you can check below link.
Accessing the Activity from a Fragment