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 .NET WebForms example #537

Merged
merged 2 commits into from
Nov 30, 2017
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
5 changes: 3 additions & 2 deletions ExampleNet45ASPNetProject/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ Update the "SendGridApiKey" appSettings variable within the web.config file.

## Steps

1. Open SendGrid.ASPSamples.sln
2. Build the solution and run the project
1. Open SendGrid.ASPSamples.sln
2. Switch to one of the example project (right click on a project -> "Set as StartUp project")
2. Build and run the project

You may need to download the latest Nuget executable and run `nuget.exe restore`

Expand Down
13 changes: 11 additions & 2 deletions ExampleNet45ASPNetProject/SendGrid.ASPSamples.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendGrid.ASPSamples", "SendGrid.ASPSamples\SendGrid.ASPSamples.csproj", "{14FA0F22-DFB2-4CE2-867A-242E75F64E1B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendGrid.ASPWebFormsSamples", "SendGrid.ASPWebFormsSamples\SendGrid.ASPWebFormsSamples.csproj", "{0A24E647-5885-477C-A766-7385BCC6982E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,8 +17,15 @@ Global
{14FA0F22-DFB2-4CE2-867A-242E75F64E1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14FA0F22-DFB2-4CE2-867A-242E75F64E1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{14FA0F22-DFB2-4CE2-867A-242E75F64E1B}.Release|Any CPU.Build.0 = Release|Any CPU
{0A24E647-5885-477C-A766-7385BCC6982E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A24E647-5885-477C-A766-7385BCC6982E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A24E647-5885-477C-A766-7385BCC6982E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A24E647-5885-477C-A766-7385BCC6982E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {36445F8F-3714-4B6A-89DB-17DC0C001CF5}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Wrap content on words otherwise the body response overflows in the Well*/
.well {
word-wrap: break-word;
}

/* Move down content because we have a fixed navbar that is 50px tall */
body {
padding-top: 50px;
padding-bottom: 20px;
}

/* Wrapping element */
/* Set some basic padding to keep content from hitting the edges */
.body-content {
padding-left: 15px;
padding-right: 15px;
margin-top: 50px;
}

/* Responsive: Portrait tablets and up */
@media screen and (min-width: 768px) {
.body-content {
padding: 0;
}
}


64 changes: 64 additions & 0 deletions ExampleNet45ASPNetProject/SendGrid.ASPWebFormsSamples/Default.aspx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<%@ Page Title="Home Page" Async="true" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SendGrid.ASPWebFormsSamples.Default" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="row">
<div class="col-md-4">
<div class="form-horizontal">
<div class="form-group">
<label class="col-md-2 control-label">From: </label>
<div class="col-md-10">
<input id="fromInput" runat="server" type="text" class="form-control" />
</div>
</div>

<div class="form-group">
<label class="col-md-2 control-label">To: </label>
<div class="col-md-10">
<input id="toInput" runat="server" type="text" class="form-control"/>
</div>
</div>

<div class="form-group">
<label class="col-md-2 control-label">Cc: </label>
<div class="col-md-10">
<input id="ccInput" runat="server" type="text" class="form-control"/>
</div>
</div>

<div class="form-group">
<label class="col-md-2 control-label">Bcc: </label>
<div class="col-md-10">
<input id="bccInput" runat="server" type="text" class="form-control"/>
</div>
</div>

<div class="form-group">
<label class="col-md-2 control-label">Subject: </label>
<div class="col-md-10">
<input id="subjectInput" runat="server" type="text" class="form-control"/>
</div>
</div>

<div class="form-group">
<label class="col-md-2 control-label">Body: </label>
<div class="col-md-10">
<textarea id="bodyInput" runat="server" cols="20" rows="10" class="form-control"></textarea>
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<asp:Button ID="sendButton" runat="server" Text="Send" OnClick="sendButton_Click" CssClass="btn btn-default pull-right"/>
</div>
</div>
</div>
</div>

<div id="responseInfo" runat="server" class="col-md-8">
<div id="responseStatus" runat="server" class="alert alert-info" role="alert"></div>

<span>Response body: </span>
<div runat="server" id="responseBody" class="well"></div>
</div>
</div>
</asp:Content>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Threading.Tasks;
using System.Web.UI;
using SendGrid.ASPWebFormsSamples.Models;
using SendGrid.ASPWebFormsSamples.Services;

namespace SendGrid.ASPWebFormsSamples
{
public partial class Default : Page
{
private readonly SendGridService _sendGridService;

protected Default()
{
_sendGridService = new SendGridService();
}

protected void Page_Load(object sender, EventArgs e)
{
responseInfo.Visible = false;
}

protected async void sendButton_Click(object sender, EventArgs e)
{
// Prepare the email message info model
var messageInfo = new EmailMessageInfo
{
FromEmailAddress = fromInput.Value,
ToEmailAddress = toInput.Value,
CcEmailAddress = ccInput.Value,
BccEmailAddress = bccInput.Value,
EmailSubject = subjectInput.Value,
EmailBody = bodyInput.Value
};

// Make an API call, and save the response
var apiResponse = await _sendGridService.Send(messageInfo);

await SetResponseInfoContainers(apiResponse);
}

private async Task SetResponseInfoContainers(Response apiResponse)
{
responseInfo.Visible = true;
responseStatus.InnerText = $"Statuscode {(int)apiResponse.StatusCode}: {apiResponse.StatusCode}";
responseBody.InnerText = await apiResponse.Body.ReadAsStringAsync();
}
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%@ Application Codebehind="Global.asax.cs" Inherits="SendGrid.ASPWebFormsSamples.Global" Language="C#" %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Web;

namespace SendGrid.ASPWebFormsSamples
{
public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace SendGrid.ASPWebFormsSamples.Models
{
public class EmailMessageInfo
{
public string FromEmailAddress { get; set; }

public string ToEmailAddress { get; set; }

public string CcEmailAddress { get; set; }

public string BccEmailAddress { get; set; }

public string EmailSubject { get; set; }

public string EmailBody { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SendGrid.ASPWebFormsSamples")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SendGrid.ASPWebFormsSamples")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("0a24e647-5885-477c-a766-7385bcc6982e")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading