Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Code for Editing your existing email message content inside Android App

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 23-05-2014
Member
 
Join Date: May 2014
Posts: 1
Code for Editing your existing email message content inside Android App
  

This technical tip shows how to load any existing email message and modify its contents before saving it back to disk using Aspose.Email for Android API. To do this successfully, specify the MessageFormat when loading the email message from disk. In addition, it is important to specify the correct MailMessageSaveType when saving the message back to disk.

To update and save an email, the following steps can be used:

1. Create an instance of the MailMessage class.
2. Load an existing message using the MailMessage class' load() method and specifying the MessageFormat of the existing message.
3. Get the subject using getSubject().
4. After modifying the subject, set it again using the setSubject() method.
5. Get the body using getHtmlBody().
6. After modifying the body, set it using the setHtmlBody() method .
7. Create an instance of the MailAddressCollection class.
8. Get the recipients from the TO field into a MailAddressCollection object using the getTo() method exposed by the MailMessage class.
9. Add or remove recipients using the add() and remove() methods exposed by the MailAddressCollection class.
10. Get the recipients from the CC field into a MailAddressCollection object using the getCC() method exposed by MailMessage class.
11. Add or remove recipients using the add() and remove() methods exposed by the MailAddressCollection class.
12. Call the save() method exposed by the MailMessage class, specifying the correct MailMessageSaveType to save the message file to the disk in MSG format.



Code:
public static void UpdateAndSaveEmail()
{
    // Base folder for reading and writing files
String  strBaseFolder  = Environment.getExternalStorageDirectory().getPath();
strBaseFolder = strBaseFolder + "/";

    //Initialize and load an existing MSG file by specifying the MessageFormat
MailMessage email = MailMessage.load(strBaseFolder + "anEmail.msg", MessageFormat.getMsg());

    //Initialize a String variable to get the Email Subject
    String subject = email.getSubject();
    //Append some more information to Subject
subject = subject + " This text is added to the existing subject";
    //Set the Email Subject
email.setSubject(subject);

    //Initialize a String variable to get the Email's HTML Body
    String body = email.getHtmlBody();
    //Apppend some more information to the Body variable
body = body + "<br> This text is added to the existing body";
    //Set the Email Body
email.setHtmlBody(body);

    //Initialize MailAddressCollection object
MailAddressCollection contacts = new MailAddressCollection();

    //Retrieve Email's TO list
contacts = email.getTo();
    //Check if TO list has some values
if (contacts.size() > 0)
    {
        //Remove the first email address
contacts.remove(0);
        //Add another email address to collection
contacts.add("to1@domain.com");
    }
    //Set the collection as Email's TO list
email.setTo(contacts);

    //Initialize MailAddressCollection
contacts = new MailAddressCollection();

    //Retrieve Email's CC list
contacts = email.getCC();
    //Add another email address to collection
contacts.add("cc2@domain.com");
    //Set the collection as Email's CC list
email.setCC(contacts);

    //Save the Email message to disk by specifying the MessageFormat
email.save(strBaseFolder + "message.msg", MailMessageSaveType.getOutlookMessageFormat());

Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Code for Editing your existing email message content inside Android App"
Thread Thread Starter Forum Replies Last Post
Avast is not able to check email when set to ssl inside thunderbird Eeshika18 Networking & Security 6 19-12-2011 03:55 PM
Can I use existing Email account of office 365 with Outlook/Exchange service Eliasz Windows Software 5 30-07-2011 10:31 PM
Replacing Existing Reg Code Jake Tyler Windows Software 4 11-06-2010 01:49 PM
I need JAVA help code inside Daren Software Development 3 23-05-2009 06:58 PM
how to insert html code into email message? MikeY007 MS Office Support 1 29-01-2008 07:12 PM


All times are GMT +5.5. The time now is 04:17 AM.