Skip to content

agenthunt/react-native-mailcore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-mailcore

react native bindings for https://github.com/MailCore/mailcore2

npm version npm downloads

Stability status: alpha

Setup

  • yarn add react-native-mailcore

  • react-native link react-native-mailcore

  • For ios, setup pods for your project. Go to ios directory in your project. See https://github.com/MailCore/mailcore2/blob/master/build-mac/README.md#cocoapods

    • If you havent setup pods for your project run pod init in your ios directory.

    • Add pod 'mailcore2-ios' to your Podfile. Example

        # Uncomment the next line to define a global platform for your project
        # platform :ios, '9.0'
      
        target 'BasicExample' do
          # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
          # use_frameworks!
      
          # Pods for BasicExample
      
          pod 'mailcore2-ios'
      
          target 'BasicExampleTests' do
            inherit! :search_paths
            # Pods for testing
          end
      
        end
      
        target 'BasicExample-tvOS' do
          # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
          # use_frameworks!
      
          # Pods for BasicExample-tvOS
      
          target 'BasicExample-tvOSTests' do
            inherit! :search_paths
            # Pods for testing
          end
      
        end
      
    • pod install

  • For android,

    • copy paste the following lines in to settings.gradle
    include ':mailcore2-android-4'
    project(':mailcore2-android-4').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mailcore/mailcore2-android-4')
    
    • Add the following code to app/build.gradle of your app.

      • For android tools version com.android.tools.build:gradle:2.2.3

          import com.android.build.gradle.internal.pipeline.TransformTask
        
          def deleteDuplicateJniFiles() {
              def files = fileTree("${buildDir}/intermediates/exploded-aar/com.facebook.react/react-native/0.43.3/jni/") {
                  include "**/libgnustl_shared.so"
              }
              files.each { it.delete() }
          }
        
          tasks.withType(TransformTask) { pkgTask ->
              pkgTask.doFirst { deleteDuplicateJniFiles() }
          }
        
        • Make sure to change the react-native version properly
      • For android tools version com.android.tools.build:gradle:2.3.3

        android {
          ...
          ...
          ...
          ...
          ...
            packagingOptions{
                pickFirst '**/libgnustl_shared.so'
            }
        }
        

Usage

  • Note: For any of the following methods you must first use loginImap
  • Note: For SendMail method you must first use loginSmtp
  • Note: For the use of attachments download remember to give permission to the application
import MailCore from "react-native-mailcore";
  • Login smtp
MailCore.loginSmtp({
  hostname: "smtp.gmail.com",
  port: 465,
  username: "[email protected]",
  password: "password",
})
  .then((result) => {
    alert(result.status);
  })
  .catch((error) => {
    alert(error);
  });
  • Login imap
MailCore.loginImap({
  hostname: "imap.gmail.com",
  port: 993,
  username: "[email protected]",
  password: "password",
})
  .then((result) => {
    alert(result.status);
  })
  .catch((error) => {
    alert(error);
  });
  • Create Folder
MailCore.createFolder({
  folder: "newfoldername",
})
  .then((result) => {
    alert(result.status);
  })
  .catch((error) => {
    alert(error);
  });
  • List folders
MailCore.getFolders()
  .then((result) => {
    const a = [...result.folders];
    a.forEach((element) => {
      alert(element.path);
    });
  })
  .catch((error) => {
    alert(error);
  });
  • Move Email
MailCore.moveEmail({
  folderFrom: "oldfolder",
  messageId: 14,
  folderTo: "newfolder",
})
  .then((result) => {
    alert(result.status);
  })
  .catch((error) => {
    alert(error);
  });
  • Permant Email Delete
MailCore.permantDeleteEmail({
  folderFrom: "folder",
  messageId: messageId,
})
  .then((result) => {
    alert(result.status);
  })
  .catch((error) => {
    alert(error);
  });
  • Action Flag Message
  MailCore.actionFlagMessage({
    folder: 'folder',
    messageId: messageId,
    flagsRequestKind: <FlagsRequestKind val int>,
    messageFlag: <MessageFlag val int>
  })
  .then(result => {
      alert(result.status);
  })
  .catch(error => {
      alert(error);

  });
  • Action label Message
    MailCore.actionLabelMessage({
      folder: 'folder',
      messageId: messageId,
      flagsRequestKind: <FlagsRequestKind val int>,
      tags: ["tag1","tag2","tag3"]
    })
    .then(result => {
        alert(result.status);
    })
    .catch(error => {
        alert(error);
    });
  • Rename folder
MailCore.renameFolder({
  folderOldName: "oldFolderName",
  folderNewName: "newFolderName",
})
  .then((result) => {
    alert(result.status);
  })
  .catch((error) => {
    alert(error);
  });
  • Delete folder
MailCore.deleteFolder({
  folder: "folderName",
})
  .then((result) => {
    alert(result.status);
  })
  .catch((error) => {
    alert(error);
  });
  • List folders
MailCore.getFolders()
  .then((result) => {
    const a = [...result.folders];
    a.forEach((element) => {
      alert(element.path);
    });
  })
  .catch((error) => {
    alert(error);
  });
  • Move Email
MailCore.moveEmail({
  folderFrom: "oldfolder",
  messageId: 14,
  folderTo: "newfolder",
})
  .then((result) => {
    alert(result.status);
  })
  .catch((error) => {
    alert(error);
  });
  • Permant Email Delete
MailCore.permantDeleteEmail({
  folderFrom: "folder",
  messageId: messageId,
})
  .then((result) => {
    alert(result.status);
  })
  .catch((error) => {
    alert(error);
  });
  • Action Flag Message
  MailCore.actionFlagMessage({
    folder: 'folder',
    messageId: messageId,
    flagsRequestKind: <FlagsRequestKind val int>,
    messageFlag: <MessageFlag val int>
  })
  .then(result => {
      alert(result.status);
  })
  .catch(error => {
      alert(error);

  });
  • Action label Message
  MailCore.actionLabelMessage({
    folder: 'folder',
    messageId: messageId,
    flagsRequestKind: <FlagsRequestKind val int>,
    tags: ["tag1","tag2","tag3"]
  })
  .then(result => {
      alert(result.status);
  })
  .catch(error => {
      alert(error);
  });
  • Send Mail
MailCore.sendMail({
  headers: {
    key: "value",
  },
  from: {
    addressWithDisplayName: "from label",
    mailbox: "[email protected]",
  },
  to: {
    "[email protected]": "to label",
    "[email protected]": "to label",
  },
  cc: {
    "[email protected]": "cc label",
    "[email protected]": "cc label",
  },
  bcc: {
    "[email protected]": "bcc label",
    "[email protected]": "bcc label",
  },
  subject: "subject",
  body: "body",
  attachments: ["url/filename", "url/filename"],
})
  .then((result) => {
    alert(result.status);
  })
  .catch((error) => {
    alert(error);
  });
  • Get mail
  MailCore.getMail({
  folder: 'folder',
  messageId: messageId,
  requestKind: <IMAPMessagesRequestKind val int>
  })
  .then(result => {
    let mail = {
      id: result.id,
      date: result.date,
      from: result.from,
      to: result.to,
      cc: result.cc,
      bcc: result.bcc,
      subject: result.subject,
      body: result.body,
      attachments: result.attachments
    }
    alert(result.status);
    console.log(mail)
  })
  .catch(error => {
      alert(error);
  });
  • Get Attachment
MailCore.getAttachment({
  filename: "filename",
  folder: "folder",
  messageId: messageId,
  partID: "partID",
  encoding: encoding,
  folderOutput: "urlOutput",
})
  .then((result) => {
    alert(result.status);
  })
  .catch((error) => {
    alert(error);
  });
* Get Attachment Inline (Android)
* In IOS the inline attachment comes in the getmail mail method
MailCore.getAttachmentInline({
  filename: "filename",
  folder: "folder",
  messageId: messageId,
  partID: "partID",
  encoding: encoding,
  mimepart: "image/png",
})
  .then((result) => {
    alert(result.status);
  })
  .catch((error) => {
    alert(error);
  });
  • List mails
  MailCore.getMails({
    folder: 'folder',
    requestKind: <IMAPMessagesRequestKind int value>
  })
  .then(result => {
    let promises = [];
    for (let i=0; i<result.mails.length;i++) {
      let mail = result.mails[i];
      let promise = new Promise((resolve,reject) => {
        MailCore.getMail({
          folder: 'folder',
          messageId: mail.id,
          requestKind: <IMAPMessagesRequestKind int value>
          }).then(mailDetails => {
            mail.body = mailDetails.body
            resolve(mail);
          })
          .catch(error => reject(error))
      });
      promises.push(promise)
    }
    Promise.all(promises)
    .then(mails =>
      console.log(mails))
  })
  .catch(error => {
      alert(error);
  });
}

TODO

  • createFolder API support
  • renameFolder API support
  • deleteFolder API support
  • listFolders API support
  • imapLogin API support
  • smtpLogin API support
  • GetEmail API support
  • MoveEmail API support
  • DeleteEmail API support
  • Download attachment
  • SendEmail with attachments
  • addFlags API support
  • deleteFlags API support
  • GetEmails API support
  • Basic Example