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

Add support for inline attachments for SendGrid #361

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
90 changes: 90 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Publish Packages

on:
push:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore

- name: Publish FluentEmail.Core
uses: brandedoutcast/[email protected]
with:
PROJECT_FILE_PATH: src/FluentEmail.Core/FluentEmail.Core.csproj
VERSION_FILE_PATH: src/Directory.Build.props
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
NUGET_SOURCE: https://api.nuget.org
INCLUDE_SYMBOLS: true
- name: Publish FluentEmail.Smtp
uses: brandedoutcast/[email protected]
with:
PROJECT_FILE_PATH: src/Senders/FluentEmail.Smtp/FluentEmail.Smtp.csproj
VERSION_FILE_PATH: src/Directory.Build.props
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
NUGET_SOURCE: https://api.nuget.org
INCLUDE_SYMBOLS: true
- name: Publish FluentEmail.Sendgrid
uses: brandedoutcast/[email protected]
with:
PROJECT_FILE_PATH: src/Senders/FluentEmail.SendGrid/FluentEmail.SendGrid.csproj
VERSION_FILE_PATH: src/Directory.Build.props
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
NUGET_SOURCE: https://api.nuget.org
INCLUDE_SYMBOLS: true
#- name: Publish FluentEmail.MailTrap
# uses: brandedoutcast/[email protected]
# with:
# PROJECT_FILE_PATH: src/Senders/FluentEmail.Mailtrap/FluentEmail.Mailtrap.csproj
# NUGET_KEY: ${{secrets.NUGET_API_KEY}}
# NUGET_SOURCE: https://api.nuget.org
- name: Publish FluentEmail.MailKit
uses: brandedoutcast/[email protected]
with:
PROJECT_FILE_PATH: src/Senders/FluentEmail.MailKit/FluentEmail.MailKit.csproj
VERSION_FILE_PATH: src/Directory.Build.props
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
NUGET_SOURCE: https://api.nuget.org
INCLUDE_SYMBOLS: true
- name: Publish FluentEmail.Mailgun
uses: brandedoutcast/[email protected]
with:
PROJECT_FILE_PATH: src/Senders/FluentEmail.Mailgun/FluentEmail.Mailgun.csproj
VERSION_FILE_PATH: src/Directory.Build.props
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
NUGET_SOURCE: https://api.nuget.org
INCLUDE_SYMBOLS: true
- name: Publish FluentEmail.Razor
uses: brandedoutcast/[email protected]
with:
PROJECT_FILE_PATH: src/Renderers/FluentEmail.Razor/FluentEmail.Razor.csproj
VERSION_FILE_PATH: src/Directory.Build.props
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
NUGET_SOURCE: https://api.nuget.org
INCLUDE_SYMBOLS: true
- name: Publish FluentEmail.Liquid
uses: brandedoutcast/[email protected]
with:
PROJECT_FILE_PATH: src/Renderers/FluentEmail.Liquid/FluentEmail.Liquid.csproj
VERSION_FILE_PATH: src/Directory.Build.props
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
NUGET_SOURCE: https://api.nuget.org
INCLUDE_SYMBOLS: true
# This is currently maintained separately
#- name: Publish FluentEmail.Graph
# uses: brandedoutcast/[email protected]
# with:
# PROJECT_FILE_PATH: src/Senders/FluentEmail.Graph/FluentEmail.Graph.csproj
# NUGET_KEY: ${{secrets.NUGET_API_KEY}}
# NUGET_SOURCE: https://api.nuget.org
4 changes: 3 additions & 1 deletion src/Senders/FluentEmail.SendGrid/SendGridSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ private async Task<SendResponse> SendViaSendGrid(SendGridMessage mailMessage, Ca
{
Content = await GetAttachmentBase64String(attachment.Data),
Filename = attachment.Filename,
Type = attachment.ContentType
Type = attachment.ContentType,
ContentId = attachment.ContentId,
Disposition = attachment.IsInline ? "inline" : "attachment"
};

private async Task<string> GetAttachmentBase64String(Stream stream)
Expand Down
33 changes: 33 additions & 0 deletions test/FluentEmail.Core.Tests/SendGridSenderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,38 @@ public async Task CanSendLowPriorityEmail()

Assert.IsTrue(response.Successful);
}

[Test, Ignore("No sendgrid credentials")]
public async Task CanSendEmailWithInlineAttachments()
{
// Arrange
const string subject = "SendMail With Inline Attachments Test";
const string body = "This email is testing the inline attachment functionality of SendGrid Sender.";

using (var stream = File.OpenRead($"{Directory.GetCurrentDirectory()}/logotest.png"))
{
var attachment = new Attachment
{
Data = stream,
ContentType = "image/png",
Filename = "logotest.png",
IsInline = true,
ContentId = "logotest_id"
};

var email = Email
.From(fromEmail, fromName)
.To(toEmail, toName)
.Subject(subject)
.Body(body)
.Attach(attachment);

// Act
var response = await email.SendAsync();

// Assert
Assert.IsTrue(response.Successful);
}
}
}
}