Save email message as eml using C# in Lotus Notes










3















I need to export (save to) hard drive my Lotus Notes emails.
I figured out the way how to save attachments to HDD, but I can't figure out the way of how to save the whole email.



The code below shows how I export attachments. Can you suggest how can I modify it to save emails?
PS- I am new to programming.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domino;
using System.Collections;

namespace ExportLotusAttachments

class Class1

public void ScanForEmails()

String textBox1 = "c:\1";
NotesSession session = new NotesSession();
session.Initialize("");
NotesDbDirectory dir = null;
dir = session.GetDbDirectory("");
NotesDatabase db = null;
db = dir.OpenMailDatabase();
NotesDatabase NDb = dir.OpenMailDatabase(); //Database connection

//ArrayList that will hold names of the folders
ArrayList LotusViews2 = new ArrayList();

foreach (NotesView V in NDb.Views)

if (V.IsFolder && !(V.Name.Equals("($All)")))

NotesView getS = V;
LotusViews2.Add(getS.Name);



foreach (String obj in LotusViews2)

NotesDocument NDoc;
NotesView nInboxDocs = NDb.GetView(obj);
NDoc = nInboxDocs.GetFirstDocument();
String pAttachment;

while (NDoc != null)

if (NDoc.HasEmbedded && NDoc.HasItem("$File"))

object AllDocItems = (object)NDoc.Items;
foreach (object CurItem in AllDocItems)

NotesItem nItem = (NotesItem)CurItem;
if (IT_TYPE.ATTACHMENT == nItem.type)

String path = textBox1;
pAttachment = ((object)nItem.Values)[0].ToString();

if (!System.IO.Directory.Exists(path))

System.IO.Directory.CreateDirectory(textBox1);


try

NDoc.GetAttachment(pAttachment).ExtractFile(@path + pAttachment);

catch



NDoc = nInboxDocs.GetNextDocument(NDoc);














share|improve this question
























  • Please preview your code (you can do that by looking below the area you're typing it) for formatting before posting it. It not only makes your question more readable, it saves time because other people don't have to spend theirs fixing it. :) The easier it is for people to read and understand, the more likely you are to get an answer. Thanks.

    – Ken White
    Dec 9 '11 at 23:45















3















I need to export (save to) hard drive my Lotus Notes emails.
I figured out the way how to save attachments to HDD, but I can't figure out the way of how to save the whole email.



The code below shows how I export attachments. Can you suggest how can I modify it to save emails?
PS- I am new to programming.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domino;
using System.Collections;

namespace ExportLotusAttachments

class Class1

public void ScanForEmails()

String textBox1 = "c:\1";
NotesSession session = new NotesSession();
session.Initialize("");
NotesDbDirectory dir = null;
dir = session.GetDbDirectory("");
NotesDatabase db = null;
db = dir.OpenMailDatabase();
NotesDatabase NDb = dir.OpenMailDatabase(); //Database connection

//ArrayList that will hold names of the folders
ArrayList LotusViews2 = new ArrayList();

foreach (NotesView V in NDb.Views)

if (V.IsFolder && !(V.Name.Equals("($All)")))

NotesView getS = V;
LotusViews2.Add(getS.Name);



foreach (String obj in LotusViews2)

NotesDocument NDoc;
NotesView nInboxDocs = NDb.GetView(obj);
NDoc = nInboxDocs.GetFirstDocument();
String pAttachment;

while (NDoc != null)

if (NDoc.HasEmbedded && NDoc.HasItem("$File"))

object AllDocItems = (object)NDoc.Items;
foreach (object CurItem in AllDocItems)

NotesItem nItem = (NotesItem)CurItem;
if (IT_TYPE.ATTACHMENT == nItem.type)

String path = textBox1;
pAttachment = ((object)nItem.Values)[0].ToString();

if (!System.IO.Directory.Exists(path))

System.IO.Directory.CreateDirectory(textBox1);


try

NDoc.GetAttachment(pAttachment).ExtractFile(@path + pAttachment);

catch



NDoc = nInboxDocs.GetNextDocument(NDoc);














share|improve this question
























  • Please preview your code (you can do that by looking below the area you're typing it) for formatting before posting it. It not only makes your question more readable, it saves time because other people don't have to spend theirs fixing it. :) The easier it is for people to read and understand, the more likely you are to get an answer. Thanks.

    – Ken White
    Dec 9 '11 at 23:45













3












3








3


1






I need to export (save to) hard drive my Lotus Notes emails.
I figured out the way how to save attachments to HDD, but I can't figure out the way of how to save the whole email.



The code below shows how I export attachments. Can you suggest how can I modify it to save emails?
PS- I am new to programming.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domino;
using System.Collections;

namespace ExportLotusAttachments

class Class1

public void ScanForEmails()

String textBox1 = "c:\1";
NotesSession session = new NotesSession();
session.Initialize("");
NotesDbDirectory dir = null;
dir = session.GetDbDirectory("");
NotesDatabase db = null;
db = dir.OpenMailDatabase();
NotesDatabase NDb = dir.OpenMailDatabase(); //Database connection

//ArrayList that will hold names of the folders
ArrayList LotusViews2 = new ArrayList();

foreach (NotesView V in NDb.Views)

if (V.IsFolder && !(V.Name.Equals("($All)")))

NotesView getS = V;
LotusViews2.Add(getS.Name);



foreach (String obj in LotusViews2)

NotesDocument NDoc;
NotesView nInboxDocs = NDb.GetView(obj);
NDoc = nInboxDocs.GetFirstDocument();
String pAttachment;

while (NDoc != null)

if (NDoc.HasEmbedded && NDoc.HasItem("$File"))

object AllDocItems = (object)NDoc.Items;
foreach (object CurItem in AllDocItems)

NotesItem nItem = (NotesItem)CurItem;
if (IT_TYPE.ATTACHMENT == nItem.type)

String path = textBox1;
pAttachment = ((object)nItem.Values)[0].ToString();

if (!System.IO.Directory.Exists(path))

System.IO.Directory.CreateDirectory(textBox1);


try

NDoc.GetAttachment(pAttachment).ExtractFile(@path + pAttachment);

catch



NDoc = nInboxDocs.GetNextDocument(NDoc);














share|improve this question
















I need to export (save to) hard drive my Lotus Notes emails.
I figured out the way how to save attachments to HDD, but I can't figure out the way of how to save the whole email.



The code below shows how I export attachments. Can you suggest how can I modify it to save emails?
PS- I am new to programming.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domino;
using System.Collections;

namespace ExportLotusAttachments

class Class1

public void ScanForEmails()

String textBox1 = "c:\1";
NotesSession session = new NotesSession();
session.Initialize("");
NotesDbDirectory dir = null;
dir = session.GetDbDirectory("");
NotesDatabase db = null;
db = dir.OpenMailDatabase();
NotesDatabase NDb = dir.OpenMailDatabase(); //Database connection

//ArrayList that will hold names of the folders
ArrayList LotusViews2 = new ArrayList();

foreach (NotesView V in NDb.Views)

if (V.IsFolder && !(V.Name.Equals("($All)")))

NotesView getS = V;
LotusViews2.Add(getS.Name);



foreach (String obj in LotusViews2)

NotesDocument NDoc;
NotesView nInboxDocs = NDb.GetView(obj);
NDoc = nInboxDocs.GetFirstDocument();
String pAttachment;

while (NDoc != null)

if (NDoc.HasEmbedded && NDoc.HasItem("$File"))

object AllDocItems = (object)NDoc.Items;
foreach (object CurItem in AllDocItems)

NotesItem nItem = (NotesItem)CurItem;
if (IT_TYPE.ATTACHMENT == nItem.type)

String path = textBox1;
pAttachment = ((object)nItem.Values)[0].ToString();

if (!System.IO.Directory.Exists(path))

System.IO.Directory.CreateDirectory(textBox1);


try

NDoc.GetAttachment(pAttachment).ExtractFile(@path + pAttachment);

catch



NDoc = nInboxDocs.GetNextDocument(NDoc);











c# export lotus-notes eml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 16:41









jww

53.2k40228501




53.2k40228501










asked Dec 9 '11 at 22:24









AndrewAndrew

4,516945101




4,516945101












  • Please preview your code (you can do that by looking below the area you're typing it) for formatting before posting it. It not only makes your question more readable, it saves time because other people don't have to spend theirs fixing it. :) The easier it is for people to read and understand, the more likely you are to get an answer. Thanks.

    – Ken White
    Dec 9 '11 at 23:45

















  • Please preview your code (you can do that by looking below the area you're typing it) for formatting before posting it. It not only makes your question more readable, it saves time because other people don't have to spend theirs fixing it. :) The easier it is for people to read and understand, the more likely you are to get an answer. Thanks.

    – Ken White
    Dec 9 '11 at 23:45
















Please preview your code (you can do that by looking below the area you're typing it) for formatting before posting it. It not only makes your question more readable, it saves time because other people don't have to spend theirs fixing it. :) The easier it is for people to read and understand, the more likely you are to get an answer. Thanks.

– Ken White
Dec 9 '11 at 23:45





Please preview your code (you can do that by looking below the area you're typing it) for formatting before posting it. It not only makes your question more readable, it saves time because other people don't have to spend theirs fixing it. :) The easier it is for people to read and understand, the more likely you are to get an answer. Thanks.

– Ken White
Dec 9 '11 at 23:45












2 Answers
2






active

oldest

votes


















2














This post by Bob Babalan explains how to export lotus documents using Java. The same principle should work in C# or VB. The document is cnverted into MIME and written to the disk.



Or in version 8.5.3 (I think it started witn 8.5.1) you can just drag and drop it from the mail file to the file system.






share|improve this answer


















  • 1





    Unfortunately, tha Drag & Drop to .eml functionality is not exposed via the API.

    – leyrer
    Dec 10 '11 at 9:59











  • So, there is absolutely no way of getting and saving emails to HDD?

    – Andrew
    Mar 7 '12 at 22:08











  • Sure there is, but it might require some programming as described above. The result would be a html file with the email.

    – Jasper Duizendstra
    Mar 12 '12 at 14:23











  • Bob Babalan's article provides a JavaScript solution. Unfortunately, NotesDocument.convertToMIME() is not exposed in the COM classes. Bob provided a follow-up article with sample C# using C API calls. See Here.

    – Jacob Quisenberry
    Mar 18 '13 at 17:56











  • @andrew, why the unaccept after more than a year, without explanation?

    – Jasper Duizendstra
    Nov 13 '13 at 14:25


















1














I know it is a bit late, but this is, what I did. (Based on Bob Babalan)
Bobs Solution helped me alot to understand NotesMIMEEntities, but in his solution, he only traversed the MIME-Tree to the second "layer". This will traverse multiple layers.



public static void GetMIME(StreamWriter writer, NotesMIMEEntity mimeEntity)

try

string contentType = null;
string headers = null;
string content = null;
string preamble = null;
MIME_ENCODING encoding;

contentType = mimeEntity.ContentType;
headers = mimeEntity.Headers;
encoding = mimeEntity.Encoding;

// message envelope. If no MIME-Version header, add one
if (!headers.Contains("MIME-Version:"))
writer.WriteLine("MIME-Version: 1.0");
writer.WriteLine(headers);

// for multipart, usually no main-msg content...
content = mimeEntity.ContentAsText;
if (content != null && content.Trim().Length > 0)
writer.WriteLine(content);
writer.Flush();

if (contentType.StartsWith("multipart"))

preamble = mimeEntity.Preamble;
NotesMIMEEntity mimeChild = mimeEntity.GetFirstChildEntity();

while (mimeChild != null)

GetMimeChild(writer, mimeChild);
mimeChild = mimeChild.GetNextSibling();



writer.WriteLine(mimeEntity.BoundaryEnd);
writer.Flush();

catch (Exception ex)

Logging.Log(ex.ToString());



private void GetMimeChild(StreamWriter writer, NotesMIMEEntity mimeEntity)

string contentType = null;
string headers = null;
string content = null;
string preamble = null;
MIME_ENCODING encoding;

contentType = mimeEntity.ContentType;
headers = mimeEntity.Headers;
encoding = mimeEntity.Encoding;

if (encoding == MIME_ENCODING.ENC_IDENTITY_BINARY)

mimeEntity.EncodeContent(MIME_ENCODING.ENC_BASE64);
headers = mimeEntity.Headers;


preamble = mimeEntity.Preamble;
writer.Write(mimeEntity.BoundaryStart);

if (!content.EndsWith("n"))
writer.WriteLine("");

writer.WriteLine(headers);
writer.WriteLine();

writer.Write(mimeEntity.ContentAsText);

if (contentType.StartsWith("multipart"))

preamble = mimeEntity.Preamble;
NotesMIMEEntity mimeChild = mimeEntity.GetFirstChildEntity();

while (mimeChild != null)

GetMimeChild(writer, mimeChild);
mimeChild = mimeChild.GetNextSibling();



writer.Write(mimeEntity.BoundaryEnd);
writer.Flush();



I would call this methods like this, to save the EML-File to a given path.



using (FileStream fs = new FileStream (path,FileMode.Create,FileAccess.ReadWrite,FileShare.None))

using (StreamWriter writer = new StreamWriter(fs))

NotesMimeEntity mimeEntity = notesDocument.GetMIMEEntity();
if (mimeEntity != null)
GetMIME(writer, mimeEntity);







share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8452468%2fsave-email-message-as-eml-using-c-sharp-in-lotus-notes%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    This post by Bob Babalan explains how to export lotus documents using Java. The same principle should work in C# or VB. The document is cnverted into MIME and written to the disk.



    Or in version 8.5.3 (I think it started witn 8.5.1) you can just drag and drop it from the mail file to the file system.






    share|improve this answer


















    • 1





      Unfortunately, tha Drag & Drop to .eml functionality is not exposed via the API.

      – leyrer
      Dec 10 '11 at 9:59











    • So, there is absolutely no way of getting and saving emails to HDD?

      – Andrew
      Mar 7 '12 at 22:08











    • Sure there is, but it might require some programming as described above. The result would be a html file with the email.

      – Jasper Duizendstra
      Mar 12 '12 at 14:23











    • Bob Babalan's article provides a JavaScript solution. Unfortunately, NotesDocument.convertToMIME() is not exposed in the COM classes. Bob provided a follow-up article with sample C# using C API calls. See Here.

      – Jacob Quisenberry
      Mar 18 '13 at 17:56











    • @andrew, why the unaccept after more than a year, without explanation?

      – Jasper Duizendstra
      Nov 13 '13 at 14:25















    2














    This post by Bob Babalan explains how to export lotus documents using Java. The same principle should work in C# or VB. The document is cnverted into MIME and written to the disk.



    Or in version 8.5.3 (I think it started witn 8.5.1) you can just drag and drop it from the mail file to the file system.






    share|improve this answer


















    • 1





      Unfortunately, tha Drag & Drop to .eml functionality is not exposed via the API.

      – leyrer
      Dec 10 '11 at 9:59











    • So, there is absolutely no way of getting and saving emails to HDD?

      – Andrew
      Mar 7 '12 at 22:08











    • Sure there is, but it might require some programming as described above. The result would be a html file with the email.

      – Jasper Duizendstra
      Mar 12 '12 at 14:23











    • Bob Babalan's article provides a JavaScript solution. Unfortunately, NotesDocument.convertToMIME() is not exposed in the COM classes. Bob provided a follow-up article with sample C# using C API calls. See Here.

      – Jacob Quisenberry
      Mar 18 '13 at 17:56











    • @andrew, why the unaccept after more than a year, without explanation?

      – Jasper Duizendstra
      Nov 13 '13 at 14:25













    2












    2








    2







    This post by Bob Babalan explains how to export lotus documents using Java. The same principle should work in C# or VB. The document is cnverted into MIME and written to the disk.



    Or in version 8.5.3 (I think it started witn 8.5.1) you can just drag and drop it from the mail file to the file system.






    share|improve this answer













    This post by Bob Babalan explains how to export lotus documents using Java. The same principle should work in C# or VB. The document is cnverted into MIME and written to the disk.



    Or in version 8.5.3 (I think it started witn 8.5.1) you can just drag and drop it from the mail file to the file system.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Dec 10 '11 at 8:41









    Jasper DuizendstraJasper Duizendstra

    2,2631629




    2,2631629







    • 1





      Unfortunately, tha Drag & Drop to .eml functionality is not exposed via the API.

      – leyrer
      Dec 10 '11 at 9:59











    • So, there is absolutely no way of getting and saving emails to HDD?

      – Andrew
      Mar 7 '12 at 22:08











    • Sure there is, but it might require some programming as described above. The result would be a html file with the email.

      – Jasper Duizendstra
      Mar 12 '12 at 14:23











    • Bob Babalan's article provides a JavaScript solution. Unfortunately, NotesDocument.convertToMIME() is not exposed in the COM classes. Bob provided a follow-up article with sample C# using C API calls. See Here.

      – Jacob Quisenberry
      Mar 18 '13 at 17:56











    • @andrew, why the unaccept after more than a year, without explanation?

      – Jasper Duizendstra
      Nov 13 '13 at 14:25












    • 1





      Unfortunately, tha Drag & Drop to .eml functionality is not exposed via the API.

      – leyrer
      Dec 10 '11 at 9:59











    • So, there is absolutely no way of getting and saving emails to HDD?

      – Andrew
      Mar 7 '12 at 22:08











    • Sure there is, but it might require some programming as described above. The result would be a html file with the email.

      – Jasper Duizendstra
      Mar 12 '12 at 14:23











    • Bob Babalan's article provides a JavaScript solution. Unfortunately, NotesDocument.convertToMIME() is not exposed in the COM classes. Bob provided a follow-up article with sample C# using C API calls. See Here.

      – Jacob Quisenberry
      Mar 18 '13 at 17:56











    • @andrew, why the unaccept after more than a year, without explanation?

      – Jasper Duizendstra
      Nov 13 '13 at 14:25







    1




    1





    Unfortunately, tha Drag & Drop to .eml functionality is not exposed via the API.

    – leyrer
    Dec 10 '11 at 9:59





    Unfortunately, tha Drag & Drop to .eml functionality is not exposed via the API.

    – leyrer
    Dec 10 '11 at 9:59













    So, there is absolutely no way of getting and saving emails to HDD?

    – Andrew
    Mar 7 '12 at 22:08





    So, there is absolutely no way of getting and saving emails to HDD?

    – Andrew
    Mar 7 '12 at 22:08













    Sure there is, but it might require some programming as described above. The result would be a html file with the email.

    – Jasper Duizendstra
    Mar 12 '12 at 14:23





    Sure there is, but it might require some programming as described above. The result would be a html file with the email.

    – Jasper Duizendstra
    Mar 12 '12 at 14:23













    Bob Babalan's article provides a JavaScript solution. Unfortunately, NotesDocument.convertToMIME() is not exposed in the COM classes. Bob provided a follow-up article with sample C# using C API calls. See Here.

    – Jacob Quisenberry
    Mar 18 '13 at 17:56





    Bob Babalan's article provides a JavaScript solution. Unfortunately, NotesDocument.convertToMIME() is not exposed in the COM classes. Bob provided a follow-up article with sample C# using C API calls. See Here.

    – Jacob Quisenberry
    Mar 18 '13 at 17:56













    @andrew, why the unaccept after more than a year, without explanation?

    – Jasper Duizendstra
    Nov 13 '13 at 14:25





    @andrew, why the unaccept after more than a year, without explanation?

    – Jasper Duizendstra
    Nov 13 '13 at 14:25













    1














    I know it is a bit late, but this is, what I did. (Based on Bob Babalan)
    Bobs Solution helped me alot to understand NotesMIMEEntities, but in his solution, he only traversed the MIME-Tree to the second "layer". This will traverse multiple layers.



    public static void GetMIME(StreamWriter writer, NotesMIMEEntity mimeEntity)

    try

    string contentType = null;
    string headers = null;
    string content = null;
    string preamble = null;
    MIME_ENCODING encoding;

    contentType = mimeEntity.ContentType;
    headers = mimeEntity.Headers;
    encoding = mimeEntity.Encoding;

    // message envelope. If no MIME-Version header, add one
    if (!headers.Contains("MIME-Version:"))
    writer.WriteLine("MIME-Version: 1.0");
    writer.WriteLine(headers);

    // for multipart, usually no main-msg content...
    content = mimeEntity.ContentAsText;
    if (content != null && content.Trim().Length > 0)
    writer.WriteLine(content);
    writer.Flush();

    if (contentType.StartsWith("multipart"))

    preamble = mimeEntity.Preamble;
    NotesMIMEEntity mimeChild = mimeEntity.GetFirstChildEntity();

    while (mimeChild != null)

    GetMimeChild(writer, mimeChild);
    mimeChild = mimeChild.GetNextSibling();



    writer.WriteLine(mimeEntity.BoundaryEnd);
    writer.Flush();

    catch (Exception ex)

    Logging.Log(ex.ToString());



    private void GetMimeChild(StreamWriter writer, NotesMIMEEntity mimeEntity)

    string contentType = null;
    string headers = null;
    string content = null;
    string preamble = null;
    MIME_ENCODING encoding;

    contentType = mimeEntity.ContentType;
    headers = mimeEntity.Headers;
    encoding = mimeEntity.Encoding;

    if (encoding == MIME_ENCODING.ENC_IDENTITY_BINARY)

    mimeEntity.EncodeContent(MIME_ENCODING.ENC_BASE64);
    headers = mimeEntity.Headers;


    preamble = mimeEntity.Preamble;
    writer.Write(mimeEntity.BoundaryStart);

    if (!content.EndsWith("n"))
    writer.WriteLine("");

    writer.WriteLine(headers);
    writer.WriteLine();

    writer.Write(mimeEntity.ContentAsText);

    if (contentType.StartsWith("multipart"))

    preamble = mimeEntity.Preamble;
    NotesMIMEEntity mimeChild = mimeEntity.GetFirstChildEntity();

    while (mimeChild != null)

    GetMimeChild(writer, mimeChild);
    mimeChild = mimeChild.GetNextSibling();



    writer.Write(mimeEntity.BoundaryEnd);
    writer.Flush();



    I would call this methods like this, to save the EML-File to a given path.



    using (FileStream fs = new FileStream (path,FileMode.Create,FileAccess.ReadWrite,FileShare.None))

    using (StreamWriter writer = new StreamWriter(fs))

    NotesMimeEntity mimeEntity = notesDocument.GetMIMEEntity();
    if (mimeEntity != null)
    GetMIME(writer, mimeEntity);







    share|improve this answer





























      1














      I know it is a bit late, but this is, what I did. (Based on Bob Babalan)
      Bobs Solution helped me alot to understand NotesMIMEEntities, but in his solution, he only traversed the MIME-Tree to the second "layer". This will traverse multiple layers.



      public static void GetMIME(StreamWriter writer, NotesMIMEEntity mimeEntity)

      try

      string contentType = null;
      string headers = null;
      string content = null;
      string preamble = null;
      MIME_ENCODING encoding;

      contentType = mimeEntity.ContentType;
      headers = mimeEntity.Headers;
      encoding = mimeEntity.Encoding;

      // message envelope. If no MIME-Version header, add one
      if (!headers.Contains("MIME-Version:"))
      writer.WriteLine("MIME-Version: 1.0");
      writer.WriteLine(headers);

      // for multipart, usually no main-msg content...
      content = mimeEntity.ContentAsText;
      if (content != null && content.Trim().Length > 0)
      writer.WriteLine(content);
      writer.Flush();

      if (contentType.StartsWith("multipart"))

      preamble = mimeEntity.Preamble;
      NotesMIMEEntity mimeChild = mimeEntity.GetFirstChildEntity();

      while (mimeChild != null)

      GetMimeChild(writer, mimeChild);
      mimeChild = mimeChild.GetNextSibling();



      writer.WriteLine(mimeEntity.BoundaryEnd);
      writer.Flush();

      catch (Exception ex)

      Logging.Log(ex.ToString());



      private void GetMimeChild(StreamWriter writer, NotesMIMEEntity mimeEntity)

      string contentType = null;
      string headers = null;
      string content = null;
      string preamble = null;
      MIME_ENCODING encoding;

      contentType = mimeEntity.ContentType;
      headers = mimeEntity.Headers;
      encoding = mimeEntity.Encoding;

      if (encoding == MIME_ENCODING.ENC_IDENTITY_BINARY)

      mimeEntity.EncodeContent(MIME_ENCODING.ENC_BASE64);
      headers = mimeEntity.Headers;


      preamble = mimeEntity.Preamble;
      writer.Write(mimeEntity.BoundaryStart);

      if (!content.EndsWith("n"))
      writer.WriteLine("");

      writer.WriteLine(headers);
      writer.WriteLine();

      writer.Write(mimeEntity.ContentAsText);

      if (contentType.StartsWith("multipart"))

      preamble = mimeEntity.Preamble;
      NotesMIMEEntity mimeChild = mimeEntity.GetFirstChildEntity();

      while (mimeChild != null)

      GetMimeChild(writer, mimeChild);
      mimeChild = mimeChild.GetNextSibling();



      writer.Write(mimeEntity.BoundaryEnd);
      writer.Flush();



      I would call this methods like this, to save the EML-File to a given path.



      using (FileStream fs = new FileStream (path,FileMode.Create,FileAccess.ReadWrite,FileShare.None))

      using (StreamWriter writer = new StreamWriter(fs))

      NotesMimeEntity mimeEntity = notesDocument.GetMIMEEntity();
      if (mimeEntity != null)
      GetMIME(writer, mimeEntity);







      share|improve this answer



























        1












        1








        1







        I know it is a bit late, but this is, what I did. (Based on Bob Babalan)
        Bobs Solution helped me alot to understand NotesMIMEEntities, but in his solution, he only traversed the MIME-Tree to the second "layer". This will traverse multiple layers.



        public static void GetMIME(StreamWriter writer, NotesMIMEEntity mimeEntity)

        try

        string contentType = null;
        string headers = null;
        string content = null;
        string preamble = null;
        MIME_ENCODING encoding;

        contentType = mimeEntity.ContentType;
        headers = mimeEntity.Headers;
        encoding = mimeEntity.Encoding;

        // message envelope. If no MIME-Version header, add one
        if (!headers.Contains("MIME-Version:"))
        writer.WriteLine("MIME-Version: 1.0");
        writer.WriteLine(headers);

        // for multipart, usually no main-msg content...
        content = mimeEntity.ContentAsText;
        if (content != null && content.Trim().Length > 0)
        writer.WriteLine(content);
        writer.Flush();

        if (contentType.StartsWith("multipart"))

        preamble = mimeEntity.Preamble;
        NotesMIMEEntity mimeChild = mimeEntity.GetFirstChildEntity();

        while (mimeChild != null)

        GetMimeChild(writer, mimeChild);
        mimeChild = mimeChild.GetNextSibling();



        writer.WriteLine(mimeEntity.BoundaryEnd);
        writer.Flush();

        catch (Exception ex)

        Logging.Log(ex.ToString());



        private void GetMimeChild(StreamWriter writer, NotesMIMEEntity mimeEntity)

        string contentType = null;
        string headers = null;
        string content = null;
        string preamble = null;
        MIME_ENCODING encoding;

        contentType = mimeEntity.ContentType;
        headers = mimeEntity.Headers;
        encoding = mimeEntity.Encoding;

        if (encoding == MIME_ENCODING.ENC_IDENTITY_BINARY)

        mimeEntity.EncodeContent(MIME_ENCODING.ENC_BASE64);
        headers = mimeEntity.Headers;


        preamble = mimeEntity.Preamble;
        writer.Write(mimeEntity.BoundaryStart);

        if (!content.EndsWith("n"))
        writer.WriteLine("");

        writer.WriteLine(headers);
        writer.WriteLine();

        writer.Write(mimeEntity.ContentAsText);

        if (contentType.StartsWith("multipart"))

        preamble = mimeEntity.Preamble;
        NotesMIMEEntity mimeChild = mimeEntity.GetFirstChildEntity();

        while (mimeChild != null)

        GetMimeChild(writer, mimeChild);
        mimeChild = mimeChild.GetNextSibling();



        writer.Write(mimeEntity.BoundaryEnd);
        writer.Flush();



        I would call this methods like this, to save the EML-File to a given path.



        using (FileStream fs = new FileStream (path,FileMode.Create,FileAccess.ReadWrite,FileShare.None))

        using (StreamWriter writer = new StreamWriter(fs))

        NotesMimeEntity mimeEntity = notesDocument.GetMIMEEntity();
        if (mimeEntity != null)
        GetMIME(writer, mimeEntity);







        share|improve this answer















        I know it is a bit late, but this is, what I did. (Based on Bob Babalan)
        Bobs Solution helped me alot to understand NotesMIMEEntities, but in his solution, he only traversed the MIME-Tree to the second "layer". This will traverse multiple layers.



        public static void GetMIME(StreamWriter writer, NotesMIMEEntity mimeEntity)

        try

        string contentType = null;
        string headers = null;
        string content = null;
        string preamble = null;
        MIME_ENCODING encoding;

        contentType = mimeEntity.ContentType;
        headers = mimeEntity.Headers;
        encoding = mimeEntity.Encoding;

        // message envelope. If no MIME-Version header, add one
        if (!headers.Contains("MIME-Version:"))
        writer.WriteLine("MIME-Version: 1.0");
        writer.WriteLine(headers);

        // for multipart, usually no main-msg content...
        content = mimeEntity.ContentAsText;
        if (content != null && content.Trim().Length > 0)
        writer.WriteLine(content);
        writer.Flush();

        if (contentType.StartsWith("multipart"))

        preamble = mimeEntity.Preamble;
        NotesMIMEEntity mimeChild = mimeEntity.GetFirstChildEntity();

        while (mimeChild != null)

        GetMimeChild(writer, mimeChild);
        mimeChild = mimeChild.GetNextSibling();



        writer.WriteLine(mimeEntity.BoundaryEnd);
        writer.Flush();

        catch (Exception ex)

        Logging.Log(ex.ToString());



        private void GetMimeChild(StreamWriter writer, NotesMIMEEntity mimeEntity)

        string contentType = null;
        string headers = null;
        string content = null;
        string preamble = null;
        MIME_ENCODING encoding;

        contentType = mimeEntity.ContentType;
        headers = mimeEntity.Headers;
        encoding = mimeEntity.Encoding;

        if (encoding == MIME_ENCODING.ENC_IDENTITY_BINARY)

        mimeEntity.EncodeContent(MIME_ENCODING.ENC_BASE64);
        headers = mimeEntity.Headers;


        preamble = mimeEntity.Preamble;
        writer.Write(mimeEntity.BoundaryStart);

        if (!content.EndsWith("n"))
        writer.WriteLine("");

        writer.WriteLine(headers);
        writer.WriteLine();

        writer.Write(mimeEntity.ContentAsText);

        if (contentType.StartsWith("multipart"))

        preamble = mimeEntity.Preamble;
        NotesMIMEEntity mimeChild = mimeEntity.GetFirstChildEntity();

        while (mimeChild != null)

        GetMimeChild(writer, mimeChild);
        mimeChild = mimeChild.GetNextSibling();



        writer.Write(mimeEntity.BoundaryEnd);
        writer.Flush();



        I would call this methods like this, to save the EML-File to a given path.



        using (FileStream fs = new FileStream (path,FileMode.Create,FileAccess.ReadWrite,FileShare.None))

        using (StreamWriter writer = new StreamWriter(fs))

        NotesMimeEntity mimeEntity = notesDocument.GetMIMEEntity();
        if (mimeEntity != null)
        GetMIME(writer, mimeEntity);








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 30 at 22:51

























        answered Mar 24 '16 at 10:02









        AndreasAndreas

        517211




        517211



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8452468%2fsave-email-message-as-eml-using-c-sharp-in-lotus-notes%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3

            Museum of Modern and Contemporary Art of Trento and Rovereto