Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing id parameter for attachments #61

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ MailerSend Node.js SDK
- [Usage](#usage)
- [Email](#email)
- [Send an email](#send-an-email)
- [Add CC, BCC recipients](#add-cc--bcc-recipients)
- [Add CC, BCC recipients](#add-cc-bcc-recipients)
- [Send a template-based email](#send-a-template-based-email)
- [Advanced personalization](#advanced-personalization)
- [Simple personalization](#simple-personalization)
- [Send email with attachment](#send-email-with-attachment)
- [Send email with inline attachment](#send-email-with-inline-attachment)
- [Send bulk emails](#send-bulk-emails)
- [Get bulk request status](#get-bulk-request-status)
- [Tokens](#tokens)
Expand Down Expand Up @@ -292,6 +293,45 @@ await mailerSend.email.send(emailParams);

```

### Send email with inline attachment

```js
import 'dotenv/config';
import fs from "fs";
import { MailerSend, EmailParams, Sender, Recipient, Attachment } from "mailersend";

const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});

const sentFrom = new Sender("you@yourdomain.com", "Your name");

const recipients = [
new Recipient("your@client.com", "Your Client")
];

const attachments = [
new Attachment(
fs.readFileSync('/path/to/file.png', { encoding: 'base64' }),
'file.png',
'inline',
'0123456789'
)
]

const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setReplyTo(sentFrom)
.setAttachments(attachments)
.setSubject("This is a Subject")
.setHtml("<strong>This is the HTML content with an inline image attachment <img src=\"cid:0123456789\"/></strong>")
.setText("This is the text content");

await mailerSend.email.send(emailParams);

```

### Send a scheduled email

```js
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/models/email/Attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ export class Attachment {
content: string;
filename: string;
disposition: string;
id?: string;

constructor(content: string, fileName: string, disposition: string = "attachment") {
constructor(content: string, fileName: string, disposition: string = "attachment", id?: string) {
this.content = content;
this.filename = fileName;
this.disposition = disposition;
this.id = id;
}
}