nmarus / node-ews

A simple JSON wrapper for the Exchange Web Services (EWS) SOAP API.
MIT License
115 stars 52 forks source link

Attachment #40

Open sotnikoff opened 7 years ago

sotnikoff commented 7 years ago

Is there any way to attach files to sending mails?

nmarus commented 7 years ago

Unfortunately, I don't have an example JSON request that does exactly this... However, if you start with the example in the README here which references the Microsoft article here, and drill into the Message property which has an Attachments property, you should be able to cobble the JSON request needed.

Create Email: https://msdn.microsoft.com/en-us/library/office/aa566468

Message: https://msdn.microsoft.com/en-us/library/office/aa494306

Attachment: https://msdn.microsoft.com/en-us/library/office/aa564869

vhellem commented 7 years ago

Did you find a way to solve this? @sotnikoff

roligheten commented 7 years ago

Using the links provided by @nmarus is sufficient to create the arguments. But what we also needed to do is include the following variable as the headers argument to ews.run: const ewsHeaders = { 't:RequestServerVersion': { attributes: { Version: 'Exchange2013_SP1' } }, }; Hopefully this will save someone else a couple of hours of debugging nonsensical EWS errors in the future :fox_face:

yolixtly commented 6 years ago

I just got a working example together, thanks to Catuna's ewsHeaders help above and and wanted to share!

let ews = new EWS(ewsConfig);

// define ews api function 
let ewsFunction = 'CreateItem';

// define ews api function args 
let ewsArgs = {
    attributes: {
        MessageDisposition: 'SendAndSaveCopy'
    },
    SavedItemFolderId: {
        DistinguishedFolderId: {
            attributes: {
                Id: 'sentitems'
            }
        }
    },
    Items: {
        Message: {
            ItemClass: 'IPM.Note',
            Subject: subject,
            Body: {
                attributes: {
                    BodyType: 'HTML'
                },
                $value: body
            },
            ToRecipients: {
                Mailbox: RecipientsObject.to
            },
            CcRecipients: {
                Mailbox: RecipientsObject.cc
            },
            BccRecipients: {
                Mailbox: RecipientsObject.bcc
            },
            IsRead: 'false',
            Attachments: {
                FileAttachment: [
                    {
                        Name: 'firstAttachment.txt',
                        IsInline: false,
                        IsContactPhoto: false,
                        ContentType: 'text/plain',
                        Content: 'VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4='
                    },
                    {
                        Name: 'secondAttachment.txt',
                        IsInline: false,
                        IsContactPhoto: false,
                        ContentType: 'text/plain',
                        Content: 'VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4='
                    }
                ]
            }
        }
    }
};

const ewsHeaders = { 't:RequestServerVersion': { attributes: { Version: 'Exchange2013_SP1' } }, };

ews.run(ewsFunction, ewsArgs, ewsHeaders)
    .then(() => {
        return resolve();
    })
    .catch(error => {
        console.error('Send Email Service v1 Error: ' +  error.message);
        return reject('Send Email Service v1 Error: ' + error.message);
    });
elertan commented 6 years ago

Thank god, I was about to pull my hair out 😄 ! @Catuna

dandreaf commented 4 years ago

I just got a working example together, thanks to Catuna's ewsHeaders help above and and wanted to share!

let ews = new EWS(ewsConfig);

// define ews api function 
let ewsFunction = 'CreateItem';

// define ews api function args 
let ewsArgs = {
  attributes: {
      MessageDisposition: 'SendAndSaveCopy'
  },
  SavedItemFolderId: {
      DistinguishedFolderId: {
          attributes: {
              Id: 'sentitems'
          }
      }
  },
  Items: {
      Message: {
          ItemClass: 'IPM.Note',
          Subject: subject,
          Body: {
              attributes: {
                  BodyType: 'HTML'
              },
              $value: body
          },
          ToRecipients: {
              Mailbox: RecipientsObject.to
          },
          CcRecipients: {
              Mailbox: RecipientsObject.cc
          },
          BccRecipients: {
              Mailbox: RecipientsObject.bcc
          },
          IsRead: 'false',
          Attachments: {
              FileAttachment: [
                  {
                      Name: 'firstAttachment.txt',
                      IsInline: false,
                      IsContactPhoto: false,
                      ContentType: 'text/plain',
                      Content: 'VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4='
                  },
                  {
                      Name: 'secondAttachment.txt',
                      IsInline: false,
                      IsContactPhoto: false,
                      ContentType: 'text/plain',
                      Content: 'VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4='
                  }
              ]
          }
      }
  }
};

const ewsHeaders = { 't:RequestServerVersion': { attributes: { Version: 'Exchange2013_SP1' } }, };

ews.run(ewsFunction, ewsArgs, ewsHeaders)
  .then(() => {
      return resolve();
  })
  .catch(error => {
      console.error('Send Email Service v1 Error: ' +  error.message);
      return reject('Send Email Service v1 Error: ' + error.message);
  });

how i can use FileAttachment with a file location, i mean i have 2 files .xlsx into my fileserver and i want use the file route of these files and attached into my mail. you was try that?

NikitaMigushev commented 3 years ago

I just got a working example together, thanks to Catuna's ewsHeaders help above and and wanted to share!

let ews = new EWS(ewsConfig);

// define ews api function 
let ewsFunction = 'CreateItem';

// define ews api function args 
let ewsArgs = {
    attributes: {
        MessageDisposition: 'SendAndSaveCopy'
    },
    SavedItemFolderId: {
        DistinguishedFolderId: {
            attributes: {
                Id: 'sentitems'
            }
        }
    },
    Items: {
        Message: {
            ItemClass: 'IPM.Note',
            Subject: subject,
            Body: {
                attributes: {
                    BodyType: 'HTML'
                },
                $value: body
            },
            ToRecipients: {
                Mailbox: RecipientsObject.to
            },
            CcRecipients: {
                Mailbox: RecipientsObject.cc
            },
            BccRecipients: {
                Mailbox: RecipientsObject.bcc
            },
            IsRead: 'false',
            Attachments: {
                FileAttachment: [
                    {
                        Name: 'firstAttachment.txt',
                        IsInline: false,
                        IsContactPhoto: false,
                        ContentType: 'text/plain',
                        Content: 'VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4='
                    },
                    {
                        Name: 'secondAttachment.txt',
                        IsInline: false,
                        IsContactPhoto: false,
                        ContentType: 'text/plain',
                        Content: 'VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUgYXR0YWNobWVudC4='
                    }
                ]
            }
        }
    }
};

const ewsHeaders = { 't:RequestServerVersion': { attributes: { Version: 'Exchange2013_SP1' } }, };

ews.run(ewsFunction, ewsArgs, ewsHeaders)
    .then(() => {
        return resolve();
    })
    .catch(error => {
        console.error('Send Email Service v1 Error: ' +  error.message);
        return reject('Send Email Service v1 Error: ' + error.message);
    });

how i can use FileAttachment with a file location, i mean i have 2 files .xlsx into my fileserver and i want use the file route of these files and attached into my mail. you was try that?

Hi

Have you figured out how to attach files from local storage?

dandreaf commented 3 years ago

@NikitaMigushev still not, but if you find a solution or how to do it tell me pls

ShadoKin commented 3 years ago

Has anyone solved local storage file attachment?