{"id":1103,"date":"2023-02-11T21:06:38","date_gmt":"2023-02-11T21:06:38","guid":{"rendered":"http:\/\/wp.chaoyu.nl\/?p=1103"},"modified":"2023-07-25T00:13:55","modified_gmt":"2023-07-24T22:13:55","slug":"nodejs-server-to-read-imap-mailbox-and-send-content-over-via-rest-api","status":"publish","type":"post","link":"https:\/\/chaoyu.nl\/?p=1103","title":{"rendered":"NodeJs Server To Read IMAP Mailbox and send body and attachment over via REST API, and sure let&#8217;s create docker image from it"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Imagine that you have an APEX application where it requires you to read and download attachments if there is any, also these data needs to be stored in database. These attachments can then further be processed by oracle database, thinking of a XML file or json file. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the requirements in mind, I started to search around, nodejs seems to easy enough to pick up and it also seems to meet my requirements. <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>On the database, I would make a rest call to my expressJS end point to ask a list of all new mails. <\/li>\n\n\n\n<li>Database receives JSON back with all information it asked. <\/li>\n\n\n\n<li>Database process information, if mail indicates attachments, a subsequent call is made to get the attachements <\/li>\n\n\n\n<li>Database receives it\/them and store it in table as blob<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/wp.chaoyu.nl\/wp-content\/uploads\/2023\/02\/image.png\" alt=\"\" class=\"wp-image-1105\" width=\"472\" height=\"556\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Nodejs Serve<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">On the nodejs server, I will need to endpoints to make things a little bit cleaner. They would look like something like this:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>node.chaoyu.nl\/newmails  # for header, body structure , envolope and other meta data<\/li>\n\n\n\n<li>node.chaoyu.nl\/downloadmail  # for attachment only<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">For the nodejs, I need npm to install express and imapflow<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/chaoyuim\/nodejs_mailapi\" data-type=\"URL\" data-id=\"https:\/\/github.com\/chaoyuim\/nodejs_mailapi\" target=\"_blank\" rel=\"noreferrer noopener\">Here <\/a>is my github for this project. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Test with postman<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1614\" height=\"956\" src=\"http:\/\/wp.chaoyu.nl\/wp-content\/uploads\/2023\/02\/image-2.png\" alt=\"\" class=\"wp-image-1118\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1602\" height=\"962\" src=\"http:\/\/wp.chaoyu.nl\/wp-content\/uploads\/2023\/02\/Screenshot-2023-02-12-135528.png\" alt=\"\" class=\"wp-image-1119\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Imagine that you have an APEX application where it requires you to read and download attachments if there is any, also these data needs to be stored in database. These attachments can then further be processed by oracle database, thinking of a XML file or json file. With the requirements in mind, I started to&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1124,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54,15,17],"tags":[],"class_list":["post-1103","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker","category-javascript","category-linux"],"_links":{"self":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/1103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1103"}],"version-history":[{"count":12,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/1103\/revisions"}],"predecessor-version":[{"id":1121,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/1103\/revisions\/1121"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/media\/1124"}],"wp:attachment":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}