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

Streaming attachments #1

Open
wants to merge 7 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
2 changes: 1 addition & 1 deletion SendGrid/Example/Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RESTAPI.cs" />
<Compile Include="WEBAPI.cs" />
<Compile Include="SMTPAPI.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
13 changes: 8 additions & 5 deletions SendGrid/Example/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mail;
Expand All @@ -16,21 +17,23 @@ static void Main(string[] args)
{
var username = "sgrid_username";
var password = "sgrid_password";
var from = "cj.buchmann@sendgrid.com";
var from = "bar@domain.com";
var to = new List<String>
{
"[email protected]"
"[email protected]",
"[email protected]"
};

//initialize the SMTPAPI example class
var smtpapi = new SMTPAPI(username, password, from, to);
var restapi = new RESTAPI(username, password, from, to);
var restapi = new WEBAPI(username, password, from, to);

//use this section to test out our REST and SMTP examples!
restapi.EnableTemplateEmail();
//use this section to test out our Web and SMTP examples!
smtpapi.SimpleHTMLEmail();

Console.WriteLine("Done!");
Console.ReadLine();
}

}
}
121 changes: 121 additions & 0 deletions SendGrid/Example/SMTPAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,5 +421,126 @@ public void EnableBypassListManagementEmail()
transportInstance.Deliver(message);
}

/// <summary>
/// This feature allows you to create a message template, and specify different replacement
/// strings for each specific recipient
/// </summary>
public void AddSubstitutionValues()
{
//create a new message object
var message = SendGrid.GetInstance();

//set the message recipients
foreach (string recipient in _to)
{
message.AddTo(recipient);
}

//set the sender
message.From = new MailAddress(_from);

//set the message body
message.Text = "Hi %name%! Pleased to meet you!";

//set the message subject
message.Subject = "Testing Substitution Values";

//This replacement key must exist in the message body
var replacementKey = "%name%";

//There should be one value for each recipient in the To list
var substitutionValues = new List<String> {"Mr Foo", "Mrs Raz"};

message.AddSubVal(replacementKey, substitutionValues);

//create an instance of the SMTP transport mechanism
var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));

//enable bypass list management
message.EnableBypassListManagement();

//send the mail
transportInstance.Deliver(message);
}

/// <summary>
/// This feature adds key value identifiers to be sent back as arguments over the event api for
/// various events
/// </summary>
public void AddUniqueIdentifiers()
{
//create a new message object
var message = SendGrid.GetInstance();

//set the message recipients
foreach (string recipient in _to)
{
message.AddTo(recipient);
}

//set the sender
message.From = new MailAddress(_from);

//set the message body
message.Text = "Hello World";

//set the message subject
message.Subject = "Testing Unique Identifiers";

var identifiers = new Dictionary<String, String>();
identifiers["customer"] = "someone";
identifiers["location"] = "somewhere";

message.AddUniqueIdentifiers(identifiers);

//create an instance of the SMTP transport mechanism
var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));

//enable bypass list management
message.EnableBypassListManagement();

//send the mail
transportInstance.Deliver(message);

}

/// <summary>
/// This feature tags the message with a specific tracking category, which will have aggregated stats
/// viewable from your SendGrid account page.
/// </summary>
public void SetCategory()
{
//create a new message object
var message = SendGrid.GetInstance();

//set the message recipients
foreach (string recipient in _to)
{
message.AddTo(recipient);
}

//set the sender
message.From = new MailAddress(_from);

//set the message body
message.Text = "Hello World";

//set the message subject
message.Subject = "Testing Categories";

var category = "vipCustomers";

message.SetCategory(category);

//create an instance of the SMTP transport mechanism
var transportInstance = SMTP.GetInstance(new NetworkCredential(_username, _password));

//enable bypass list management
message.EnableBypassListManagement();

//send the mail
transportInstance.Deliver(message);
}

}
}
Loading