GithubHelp home page GithubHelp logo

sendgrid / sendgrid-csharp Goto Github PK

View Code? Open in Web Editor NEW
1.1K 1.1K 588.0 9.96 MB

The Official Twilio SendGrid C#, .NetStandard, .NetCore API Library

Home Page: https://sendgrid.com

License: MIT License

C# 96.64% CSS 0.17% JavaScript 1.71% Dockerfile 0.08% HTML 0.84% Makefile 0.08% ASP.NET 0.49%
c-sharp dotnet dotnet-core dotnet-standard dotnetcore email sendgrid transactional-emails

sendgrid-csharp's Introduction

SendGrid Logo

Test and Deploy NuGet MIT licensed Twitter Follow GitHub contributors Open Source Helpers

Announcements

  • Send SMS messages with Twilio.

Overview

This library allows you to quickly and easily use the Twilio SendGrid Web API v3 via C# with .NET.

Version 9.X.X+ of this library provides full support for all Twilio SendGrid Web API v3 endpoints, including the new v3 /mail/send.

For updates to this library, see our CHANGELOG and releases.

We appreciate your continued support, thank you!

Table of Contents

Installation

Prerequisites

  • .NET Framework 4.0+
  • .NET Core 1.0+
  • .NET Standard 1.3+
  • A Twilio SendGrid account, sign up for free to send up to 40,000 emails for the first 30 days, then send 100 emails/day free forever or check out our pricing.

Obtain an API Key

Grab your API Key from the Twilio SendGrid UI.

Setup Environment Variables to Manage Your API Key

Manage your Twilio SendGrid API Keys by storing them in Environment Variables or in Web.config. It is a good practice to keep your data and configuration settings separate. This way you can change your Twilio SendGrid API key without changing your code. Also, we strongly advise against storing sensitive data directly in your code.

Setup Environment Variables using the UI:

  1. Press Win+R and run SystemPropertiesAdvanced
  2. Click on Environment Variables
  3. Click New in user variables section
  4. Type SENDGRID_API_KEY in the name. (Make sure this name matches the name of the key in your code)
  5. Type actual API Key in the value
  6. Restart the IDE and you're done!

Setup Environment Variables using CMD:

  1. Run CMD as administrator
  2. set SENDGRID_API_KEY="YOUR_API_KEY"

Here are a few examples to get and set API Keys programmatically:

# Get Environment Variable
var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");

# Set Environment Variable
var setKey = Environment.SetEnvironmentVariable("SENDGRID_API_KEY", "YOUR_API_KEY");

Install Package

To use Twilio SendGrid in your C# project, you can either download the Twilio SendGrid C# .NET libraries directly from our Github repository or if you have the NuGet package manager installed, you can grab them automatically:

dotnet add package SendGrid

# use Twilio SendGrid with HttpClientFactory
dotnet add package SendGrid.Extensions.DependencyInjection

Once you have the Twilio SendGrid library installed, you can include calls to it in your code. For sample implementations, see the .NET Core Example and the .NET 4.5.2 Example folders.

Dependencies

Please see the .csproj file.

Quick Start

Hello Email

The following is the minimum needed code to send a simple email. Use this example, and modify the apiKey, from and to variables:

using System;
using System.Threading.Tasks;
using SendGrid;
using SendGrid.Helpers.Mail;

class Program
{
    static async Task Main()
    {
        var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        var client = new SendGridClient(apiKey);
        var from = new EmailAddress("[email protected]", "Example User");
        var subject = "Sending with Twilio SendGrid is Fun";
        var to = new EmailAddress("[email protected]", "Example User");
        var plainTextContent = "and easy to do anywhere, even with C#";
        var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
        var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
        var response = await client.SendEmailAsync(msg).ConfigureAwait(false);
    }
}

After executing the above code, response.StatusCode should be 202 and you should have an email in the inbox of the to recipient. You can check the status of your email in the UI. Alternatively, we can post events to a URL of your choice using our Event Webhook. This gives you data about the events that occur as Twilio SendGrid processes your email.

For more advanced cases, you can build the SendGridMessage object yourself with these minimum required settings:

using System;
using System.Threading.Tasks;
using SendGrid;
using SendGrid.Helpers.Mail;

class Program
{
    static async Task Main()
    {
        var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        var client = new SendGridClient(apiKey);
        var msg = new SendGridMessage()
        {
            From = new EmailAddress("[email protected]", "DX Team"),
            Subject = "Sending with Twilio SendGrid is Fun",
            PlainTextContent = "and easy to do anywhere, even with C#",
            HtmlContent = "<strong>and easy to do anywhere, even with C#</strong>"
        };
        msg.AddTo(new EmailAddress("[email protected]", "Test User"));
        var response = await client.SendEmailAsync(msg).ConfigureAwait(false);
    }
}

You can find an example of all the email features here.

General v3 Web API Usage

using System;
using System.Threading.Tasks;
using SendGrid;

class Program
{
    static async Task Main()
    {
        var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        var client = new SendGridClient(apiKey);
        var queryParams = @"{'limit': 100}";
        var response = await client.RequestAsync(method: SendGridClient.Method.GET,urlPath: "suppression/bounces",
        queryParams: queryParams).ConfigureAwait(false);
    }
}

HttpClientFactory + Microsoft.Extensions.DependencyInjection

SendGrid.Extensions.DependencyInjection is required

using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using SendGrid;
using SendGrid.Extensions.DependencyInjection;
using SendGrid.Helpers.Mail;

class Program
{
    static async Task Main()
    {
        var services = ConfigureServices(new ServiceCollection()).BuildServiceProvider();
        var client = services.GetRequiredService<ISendGridClient>();
        var msg = new SendGridMessage()
        {
            From = new EmailAddress("[email protected]", "Example User"),
            Subject = "Sending with Twilio SendGrid is Fun"
        };
        msg.AddContent(MimeType.Text, "and easy to do anywhere, even with C#");
        msg.AddTo(new EmailAddress("[email protected]", "Example User"));
        var response = await client.SendEmailAsync(msg).ConfigureAwait(false);
    }

    private static IServiceCollection ConfigureServices(IServiceCollection services)
    {
        services.AddSendGrid(options =>
        {
            options.ApiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        });

        return services;
    }
}

Web Proxy

var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
var proxy = new WebProxy("http://proxy:1337");
var client = new SendGridClient(proxy, apiKey);

Or when using DependencyInjection

services.AddSendGrid(options =>
{
    options.ApiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
})
.ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler()
{
    Proxy = new WebProxy(new Uri("http://proxy:1337")),
    UseProxy = true
});

Usage

Use Cases

Here are some examples of common API use cases, such as how to send an email with a transactional template.

How to Contribute

We encourage contribution to our library (you might even score some nifty swag), please see our CONTRIBUTING guide for details.

Quick links:

Troubleshooting

Please see our troubleshooting guide for common library issues.

About

sendgrid-csharp is maintained and funded by Twilio SendGrid, Inc. The names and logos for sendgrid-csharp are trademarks of Twilio SendGrid, Inc.

Support

If you need help using SendGrid, please check the Twilio SendGrid Support Help Center.

License

The MIT License (MIT)

sendgrid-csharp's People

Contributors

0xdeafcafe avatar akunzai avatar antimatter96 avatar bobmclaren avatar brandonmwest avatar carl-hartshorn avatar cjbuchmann avatar crweiner avatar danjagnow avatar dependabot[bot] avatar dylan-asos avatar eshanholtz avatar gimly avatar jefstat avatar jennifermah avatar niladri24dutta avatar owre avatar paritoshmmmec avatar pushkyn avatar saluce65 avatar shortstuffsushi avatar shrutiburman avatar svcprodsec-sendgrid avatar tbischel avatar thepriefy avatar thinkingserious avatar tiwarishubham635 avatar twilio-ci avatar twilio-dx avatar xt0rted avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sendgrid-csharp's Issues

Attachments with accents in the name result in an error from SendGrid

When sending attachments with accents in the file name, SendGrid responds with the following error:

<result>
  <message>error</message>
  <errors>
    <error>Parameter =?utf-8?B?ZmlsZXNbTVBHw5bDicOLLnBkZl0=?= is not utf8</error>
  </errors>
 </result>

Sample code for adding the attachment to reproduce the error above is:

mailMessage.AddAttachment(fs, "MPGÖÉË.pdf");

Is this a bug in the library or with SendGrid? Or should the file name be encoded or escaped in some way?

Thanks.

SendGridMail.Transport.Web.GetInstance - Method Not Found

Getting the following exception on runtime, from the function which is trying the Web.GetInstance call.

Unhandled Exception: System.MissingMethodException: Method not found: 'SendGridM
ail.Transport.Web SendGridMail.Transport.Web.GetInstance(System.Net.NetworkCrede
ntial, Boolean)'.
at [STACKTRACE]

I think this happened when I changed from using the downloaded DLL with a normal reference, to using the latest from Nuget (1.1.1), but competely sure on that.

It's also still working when I use SMTP.GetInstance.

I think it may have to do with Nuget package manager saying it's on version 1.1.1, but the reference it installed has a Version property of 1.1.0.0.

Remove BCL Portability Pack dependencies for .NET 4.5.1 users?

I'm trying to use the SendGrid NuGet package from the Enterprise Web Library, an open-source library which itself is a NuGet package (http://www.nuget.org/packages/Ewl). We target .NET 4.5.1 and do not support earlier versions of the framework. Adding a dependency on your package will force us to take on a bunch of Microsoft.Bcl dependencies in our package, which will confuse our users.

Would it be possible for you to distribute a 4.5.1 version of your package that doesn't include those Microsoft.Bcl dependencies?

SendGridMail.Transport not found

Hi!

I downloaded the package from nuget, and tried to do the steps written in the tutorial, but i stuck at the first step: when i try to use the SendGridMail.Transport namespace, it is not in the dll, although I can use SendGridMail namespace...

Thanks,
Máté

attachments are named with the full file path

When I attach an attachment to my sendgrid message like this:
sendgridMessage.AddAttachment("c:\myFiles\test.pdf");
... then sending it via REST, the resulting email will have an attachment named "c:\myFiles\test.pdf".
This is just unuseable.

The expected result is: "test.pdf"

Exceptions in Windows Azure

Hi,

I'm sending personnalized emails from a Windows Azure worker role and I have the following errors depending on wether I use Web.Deliver() or Web.DeliverAsync():

  • Web.Deliver() exception message "One or more errors occurred." and StackTrace:
    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
    at SendGridMail.Web.Deliver(ISendGrid message)
  • Web.DeliverAsync() exception message "Could not load file or assembly 'Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified." and StackTrace:
    at SendGridMail.Web.DeliverAsync(ISendGrid message)

Does anyone has any clue on what is going on?
The second exception is telling me that an assembly is missing but I've installed SendGrid C# from the NuGet manager, it should have installed all I need... no?

Pierre

Webhooks

I'd personally love to see an example of C#/.Net use of WebHooks.

InitializeFilters not found

Is this no longer needed? The readme says it needs to be used before enabling click tracking and footers.

Errors not surfaced as I would expect in the Deliver/DeliverAsync methods

Hi,

When using the SendGrid API I was disappointed to see that errors were not surfaced as I'd expect them to be when calling deliver.
even though exceptions are thrown, I'd expect there to be either the error text or a status code such that I can determine what the errors issue is.
Any help appreciated.
Kind regards
Sean.

no interface to use file streams for attachments

When attaching files to the email, there's currently only the following interface:
public void AddAttachment(string filePath);

In many cases I don't have file but a stream, thus it's really inconvenient to work with it.
... therefore it would be really cool if you could support streams this like available in System.Net.Mail:
public Attachment(Stream contentStream, string name);

Can't add inline Images on HTML Emails (solution here)

When sending an HTML email with inlineImages, you can't....

The following code exposes enough in the SendGrid.cs class to work for my needs (ability to include file streams rather than just the Filenames would probably be handy)

There are more elegant solutions, but this one works in a pinch.

---------------Add to SendGrid.cs (in Mail project)------------

    public struct inlineImage
    {
        public inlineImage(string _FileName, string _Cid)
        {
            FileName = _FileName;
            Cid = _Cid;
        }

        public string FileName;
        public string Cid;
    }

    public List<inlineImage> htmlInlineImages = new List<inlineImage> { };

-----------Modify CreateMimeMessage's if (Html != null) block------------

        if (Html != null)
        {
            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Html, null, "text/html");
            foreach (inlineImage X in htmlInlineImages)
            {
                LinkedResource imageResource = new LinkedResource(X.FileName);
                imageResource.ContentId = X.Cid;
                htmlView.LinkedResources.Add(imageResource);
            }

            message.AlternateViews.Add(htmlView);
        }

It doesn't support the proxy

Right now there is no way to set the proxy for the rest implementation. I Forked the repo and added that features, but could be nice to have it in here and nuget :)

Using Web API from Windows Azure fails

Exception Details: System.Net.Sockets.SocketException:

[SocketException (0x271d): An attempt was made to access a socket in a way forbidden by its access permissions]
CodeScales.Http.HttpClient.Navigate(HttpRequest request, HttpBehavior httpBehavior) +772
CodeScales.Http.HttpClient.Execute(HttpRequest request) +45
SendGridMail.Transport.REST.Deliver(ISendGrid message) +115

AddCc not working when sending via the Web API

It looks like if you send via the Web API and add recipients in both the AddTo() and AddCc() method - only the ones in AddTo() will receive the email. We don't seem to send to the AddCc() addresses.
This works correctly for SMTP though.
Let me know if you need more details.
Thanks,
Andrei

change EnableTemplate to accept template_id

Need for compatibility with the new Template Engine.

{
    "filters": {
        "templates": {
            "settings": {
                "enabled": 1,
                "template_id": "5997fcf6-2b9f-484d-acd5-7e9a99f0dc1f"
            }
        }
    }
}

Create nuget package for csharp api

Please add a nuget package to http://nuget.org to make distribution and use easier.
Instructions can be found here. http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package

My reasoning is that nuget is becoming the defacto and easiest method for sharing binaries in applications on .net these days.
I am currently using a nuget package I manually created from the source, but I would like to be able to just reference one on nuget's official feed so that deployment and builds are simpler for us. Thank you.

Deprecate SMTP

We are in the process of dropping SMTP support from our libraries. The web API is 2-3 times faster for most use cases and is a smarter default, and removing it resolves some questions as to which transport to use.This also reduces the maintenance overhead of these libraries.

SMTP will be supported outside of this library, and this will allow developers to make their own choice as to what to use for SMTP transport. To make this easier we're extracting the SMTPAPI header building code into modules. Check out https://github.com/sendgrid/smtpapi-csharp

We'll have examples showing how to continue using SMTP as well.

Obviously this will be a breaking change and a version bump.

Style being removed from HTML email

I am having an issue with SendGrid stripping the style out of an HTML email I am trying to send. I am using the code provided in the ReadMe.md

I contacted SendGrid support and they advised that I open an issue here. (I think opening a ticket here seems incorrect because I do not believe this is an issue with the code in this package.)

Please provide guidance on how to debug this issue. Thanks.

Aaron

BCC and CC

Not clear how you BCC and CC multiple recipients. I could do this with an older version of this library by passing these into SendGrid.GetInstance(...)

Deprecate Support for .NET 4.0

For ease of project maintenance, I've decided to deprecate support for NET40 and move on to NET45.

The good news is that the only differences needed to run NET40 are System.Net.Http and Microsoft.Bcl.Async packages from nuget. I am hoping someone might step up and maintain a NET40-compatible fork if there is demand for it.

CRITICAL: null reference exception

Very simple code, basically the new version can't send a single email:

new Web(new NetworkCredential(login,password)).Deliver(new SendGridMessage(new MailAddress("[email protected]"),new[] { new MailAddress("[email protected]") },new MailAddress[0],new MailAddress[0],"Hello","How are you?",null));

Object reference not set to an instance of an object.

at SendGrid.Web.FetchFormParams(ISendGrid message)
at SendGrid.Web.AttachFormParams(ISendGrid message, MultipartFormDataContent content)
at SendGrid.Web.Deliver(ISendGrid message)

New Version Removes Old Functionality That Is Needed

The SendGrid.AddAttachment(Stream stream,string filename) method was removed from the nuget package version 1.0.1. While I understand most people would rather use AddAttachment(string filepath) and let sendgrid handle the reading/loading of the file, this is not acceptable for my usage. I am retrieving my files from a separate api and when I get to the point of sending I only have a MemoryStream containing the raw bytes. So to ask me to write the file back to disk just to be able to attach it to a message seems pretty silly to me. Is there any rationale behind removing that overload?

CC doesn't work on Web API

Confirmed by SendGrid Support on 4/18/2014, Our API does not currently have the 'cc' parameter.

You can't throw in AddCc() as that would break SMTP, so how exactly do you want to communicate lost recipients? I'm sure there's unintended consequences moving “CC” recipients to “TO”. "CC" recipients are currently lost through the WebAPI transport while they work fine w/the SMTP transport.

ReplayTo is Obsolete

.NET 4.5
[ObsoleteAttribute("ReplyTo is obsoleted for this type. Please use ReplyToList instead which can accept multiple addresses. http://go.microsoft.com/fwlink/?linkid=14202")]

Please implement ReplyToList:
message.ReplyToList.Add("[email protected]");

Regards,
Kent

Building App using .Net 4.0

Hello everyone.
I am not sure of this is an issue, but I was wondering if we currently still support .Net 4.0 for this current SendGrid C# library.

I am unable to build an application using this SendGrid library with .Net 4.0.
It works when building it using .Net 4.5 , but when I am building it using .Net 4.0, the following error occurs:

""The type or namespace name 'SendGridMail' could not be found (are you missing a using directive or an assembly reference?) "

Visual Studio 2012 is being used for building with both .Net 4.0 and .Net 4.5.

Please let me know if further information is needed in order to investigate this further.
Thank you.

WebApi : Web.CheckForErrors method not correctly handling error messages.

When Web.CheckForErrors is called it is expecting the errors tag to be first. But for the Deliver method the response seems to be quite different and so the message tag is being hit before the errors tag. This makes the WebApi think the message has been successful when it has not (for example when the user password is incorrect).

Web API implementation additions

I have added an implementation to the bounce portion of the web API interface. I put the proposed code on my fork (michael-lang) in a branch called IWebAPIImplementation. Take a look and let me know if you have any feedback. I plan on implementing the blocks, invalid emails, and spam report related methods as well.

  • Renamed the namespace from SendGridMail.Web to SendGridMail.WebApi. This is to prevent class name/namespace confusion. The interface in this folder was previously excluded from the project, so it shouldn't hurt backward compatibility. I did not change the root namespace of SendGridMail, as others have suggested, for backwards compatibility sake and because I think it is the appropriate name.
  • Broke out the bounce related methods from IWebApi to IBounceApi. IWebApi also implements IBounceApi. This is so that I can implement one group of methods at a time.
  • The bounce method parameter types were changed to be more strongly typed and depend on fewer magic values. The bounce list now returns a list of Bounce instead of a String.
  • Use WebClient instead of CodeScales in the bounce api. Not a change per se since it was not implemented, but I did not see a need for CodeScales. I think the rest of the library may be able to use WebClient instead as well?
  • I changed the Examples console app to be more application like and show more example code of what can be done. You can use the console app to manage the bounce list without stopping and starting the application.

Files Missing from Project

app.config and sendgrid-csharp.snk files are missing from the repository for both the Mail project and the Tests project. As a result, it's difficult to fork the project and make changes without going through and undoing all the code-signing first.

DeliverAsync is not available on ITransport interface

At the moment ITransport only has .Deliver(ISendgrid message) object. But SendGrid.Web which implements ITransport has DeliverAsync method. So if you are providing ITransport via injection, async method is not available, which is disappointing.

Require a MS SQL CLR compatible version

I am after a better more streamlined approach by using an external library with MS SQL 2012 CLR options. I cannot use the current sendgrid library for this – it is not compatible with Microsoft’s SQL Database CLR .net, and uses another DLL library as well.

We would like integrate the C# SendGrid library with a MS SQL 2012 CLR function, do you have a C# CLR version of the send grid library?

Basically we would like our database to call a windows C# program to send an email via the sendgrid library – at the moment the current one is not compatible with MS SQL due to it using a slightly different version of .net and is more restrictive.

I have setup a windows service polling our email table every 60 seconds, but if we can directly call our own CLR via a SQL function pointing to an external DLL that we could incorporate our select from email table into this would be much more efficient.

cheers.

Multiple emails per SMTP Connection

Sorry if this is the wrong place to ask questions; I wasn't sure where else to.

I'm developing an application in c# that will send lots of emails through SendGrid. Initially, I was sending them one at a time, but that was extremely slow. As I understand, I can send up to 100 emails per SMTP connection, but I'm unsure as to how exactly to do that. SendGrid support sent me here, so any help would be greatly appreciated!

Getting 'Invalid URI: The Uri string is too long.' exception from library when using the WebAPI

Hi,

I'm using the Web transport for sending complex HTML emails and from time to time, the library throws this exception:

Message: Invalid URI: The Uri string is too long.
StackTrace:
at SendGridMail.Transport.Web.CheckForErrors(IRestResponse response)
at SendGridMail.Transport.Web.Deliver(ISendGrid message)

Does anyone know how to work around this problem?

Thanks in advance.

Pierre

Azure project runtime error

Hi,

  • I made a Class Library project (SendGridService), and installed the SendGrid nuget package there and made some email sending actions
  • I referenced this class library project in an Azure service worker role project (It's also a class library) and strange thing happened: I could reference SendGridService project and it was okay to use the email sending class from the other project syntactically, but when I tried to build it said it couldn't find the refereneced assembly SendGridService, and i went mad this point :)
    Then i watched the warnings, and it said I have to reference Microsoft.Bcl.Build every project that uses SendGridMail, so i referenced SendGridService in the worker role project, and it now it's working :)

So it's not an issue, but i thought you should mention it somewhere in the readme :)

Wish you the best,
Máté

Redundant "if" in the example code

Hi

Just to ensure complete perfection please remove the "If" in the code below (as the result of this if always evaluates to true)

 if (transportWeb != null)
     transportWeb.DeliverAsync(myMessage);

Unable to send Email in Windows Azure

I'm unable to send e-mails in azure after the last update (deprecated SMTP).
I downloaded new sendgrid library from NUget in VS.
SendGrid Library doesn't report any error, but e-mails are not delivered.

                SendGrid myMessage = SendGrid.GetInstance();
                myMessage.From = new MailAddress("[email protected]");

                myMessage.Bcc = new MailAddress[] { new MailAddress(Contact.Email) };
                myMessage.Subject = "Confirmation Mail ";
                myMessage.Text = "xxxxx";

                // Create network credentials to access your SendGrid account.
                var username = "xxxx";
                var pswd = "xxxx";

                var credentials = new NetworkCredential(username, pswd);

                // Create an SMTP transport for sending email.
                var transportWeb = Web.GetInstance(credentials);

                // Send the email.
                transportWeb.DeliverAsync(myMessage);
                Contact.ErrorMessage = "xxxxx";
                return View("Contact", Contact);

SMTPAPI example doesn't work

SMTPAPI example doesn't work. Using the same credentials with WEBAPI example worked.
After looking at the java code it mentions the port 587. Adding the port 587 in C# example it worked.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.