Giter Club home page Giter Club logo

smtpapi-csharp's Introduction

Travis Badge

This module helps build SendGrid's SMTP API headers.

Announcements

All updates to this module is documented in our CHANGELOG.

Installation

Prerequisites

  • .NET version 4.5.2
  • The SendGrid service, starting at the free level)

Setup Environment Variables

Update your Environment (user space) with your SENDGRID_USERNAME and SENDGRID_PASSWORD.

Install Package

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

PM> Install-Package SendGrid.SmtpApi

Add the following namespace to use the library:

using SendGrid.CSharp.HTTP.Client;

Once you have the library properly referenced in your project, you can include calls to them in your code.

For a sample implementation, check the Example

Quick Start

using SendGrid.CSharp.HTTP.Client;

client.Host = "smtp.sendgrid.net";
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
String sendgrid_username = Environment.GetEnvironmentVariable("SENDGRID_USERNAME", EnvironmentVariableTarget.User);
String sendgrid_password = Environment.GetEnvironmentVariable("SENDGRID_PASSWORD", EnvironmentVariableTarget.User);
client.Credentials = new System.Net.NetworkCredential(sendgrid_username,sendgrid_password);

MailMessage mail = new MailMessage();
mail.To.Add(new MailAddress("[email protected]"));
mail.From = "[email protected]";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";

// add the custom header that we built above
mail.Headers.Add( "X-SMTPAPI", xmstpapiJson );

client.SendAsync(mail, null);

If you want to add multiple recipients to the X-SMTPAPI header for a mail merge type send, you can do something like the following:

var header = new Header();

var recipients = new List<String> {"[email protected]", "[email protected]", "[email protected]"};
header.SetTo(recipients);

var subs = new List<String> {"A","B","C"};
header.AddSubstitution("%name%", subs);

var mail = new MailMessage
{
    From = new MailAddress("[email protected]"),
    Subject = "Welcome",
    Body = "Hi there %name%"
};

// add the custom header that we built above
mail.Headers.Add("X-SMTPAPI", header.JsonString());

Usage

Roadmap

If you are intersted in the future direction of this project, please take a look at our milestones. We would love to hear your feedback.

How to Contribute

We encourage contribution to our projects, please see our CONTRIBUTING guide for details.

Quick links:

About

smtpapi-csharp is guided and supported by the SendGrid Developer Experience Team.

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

![SendGrid Logo] (https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)

smtpapi-csharp's People

Contributors

brandonmwest avatar thinkingserious avatar robertacosta avatar 0xdeafcafe avatar

Watchers

James Cloos avatar Jerry Huffman avatar

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.