0

I'm trying to use Html tags for sending emails just like designing template, how can i do it.

Using sendEmail method of sparkLibrary i can send only text formatted emails, how can i design templates for the email and send it.

 SparkPostEmailUtil.sendEmail(MainActivity.this,
                etSparkPostApiKey.getText().toString(),
                etSubject.getText().toString(),
                etContent.getText().toString(),
                new SparkPostSender(etSenderEmail.getText().toString(), getString(R.string.app_name)),
                new SparkPostRecipient(etRecipientEmail.getText().toString()),
                new EmailListener() {
                    @Override
                    public void onSuccess() {
                        if (progressDialog != null && progressDialog.isShowing()) {
                            progressDialog.dismiss();
                        }
                        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                        builder.setTitle("Success")
                                .setMessage("Email has been sent successfully.")
                                .show();
                    }

                    @Override
                    public void onError(String errorMessage) {
                        if (progressDialog != null && progressDialog.isShowing()) {
                            progressDialog.dismiss();
                        }
                        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                        builder.setTitle("Error Sending Email")
                                .setMessage(errorMessage)
                                .show();
                        Log.e(TAG, "Error sending SparkPost email: " + errorMessage);
                    }
                });
Krishna B N
  • 65
  • 1
  • 6

1 Answers1

1

I think you're using android-sparkpost from here which looks great for quickly sending a message. To use SparkPost's template capabilities though, you'll likely need direct access the transmissions REST API endpoint.

You could use the java-sparkpost client here to help with that. Here's an example of sending a transmission using java-sparkpost.

To use a stored template:

  1. Create your template on your account here
  2. Note the ID of your template
  3. Send a transmission with the template ID (templateId) set to your chosen template. Something like this:

    TemplateContentAttributes contentAttributes = new TemplateContentAttributes(); contentAttributes.setTemplateId("your-template-id"); transmission.setContentAttributes(contentAttributes);

Ewan Dennis
  • 396
  • 1
  • 3