Sendgrid-csharp: Create ASP.NET example

Created on 19 Feb 2017  路  12Comments  路  Source: sendgrid/sendgrid-csharp

Issue Summary

The example should demonstrate a simple web form that sends an email.

See issue 400 for follow up.

help wanted community enhancement

All 12 comments

Hi @thinkingserious I have created a ASP.NET sample to provide feature. It contains very simple feature to send email.

https://github.com/paritoshmmmec/Sendgrid-WebSample

Please let me know if you want to add more feature.

This is awesome @paritoshmmmec!

I will take a deeper look and give some feedback :)

Is there anyway you could provide a similar sample using webforms instead of MVC. I am trying to use SendGrid to verify the email address of a user when creating an account and I am having a difficult time with this. The tutorial I was using is outdated and I cannot seem to convert the code properly. I am using VS2013 web forms project and version 9.1.1 of sendgrid. I can provide my code if that would help

@vinsajon please share the codebase, happy to help.

This is the code that I added to the Email Service in the Identity Config file:
I added:
using SendGrid;
using SendGrid.Helpers.Mail;
using System.Net;
using System.Configuration;
using System.Diagnostics;

The Code:
public class EmailService : IIdentityMessageService
{
public async Task SendAsync(IdentityMessage message)
{
// Plug in your email service here to send an email.
await configSendGridasync(message);
}
private async Task configSendGridasync(IdentityMessage message)
{
var apiKey = System.Environment.GetEnvironmentVariable("APIKEY");
var client = new SendGridClient(apiKey);
var msg = new SendGridMessage()
{
From = new EmailAddress("[email protected]", "DX Team"),
Subject = "Hello World from the SendGrid CSharp SDK!",
PlainTextContent = "Hello, Email!",
HtmlContent = "Hello, Email!"
};
msg.AddTo(new EmailAddress(message.Destination));
var response = await client.SendEmailAsync(msg);
}

In the web.config file I added this:



I am not getting any errors when I create a new user, it is just redirecting to the home page as before and not sending a confirmation email. I plan on not using the webconfig file for the key in the future, I am just trying to get it to work for now. I really appreciate any help with this.

The web.config didn't get added. Here it is:
appsettings>
I left some of the brackets out on purpose

it won't let me post it but I put in add value equals APIKEY and then my apikey I got from SendGrid

Hello @vinsajon,

It looks like your issue is properly reading your APIKEY. You can verify this, by trying:

var apiKey = "YOUR_SENDGRID_API_KEY";

If the above works, it means you are having trouble retrieving the APIKEY variable from your environment.

Since it looks like you are holding the API key in your web.config, please try this.

Thanks!

@paritoshmmmec,

Thanks for offering to create the example!

I was able to get it to work. I cannot begin to thank you enough. I am mostly self taught with coding so sometimes I get stuck on simple things for a long time.
I also had to change the subject to subject = message.subject and the htmlcontext and plaintextcontext to equal message.body for the link to go through.

Hello @paritoshmmmec,

Please add the example to ExampleNet45ASPNetProject in the root directory.

Also, could you please update the README to point out where the API Key gets changed in the code and a brief explanation on how to run the example and make modifications if necessary.

Thank you!

With Best Regards,

Elmer

@thinkingserious Thanks , I will work upon it and add it

PR #464 submitted

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thinkingserious picture thinkingserious  路  4Comments

digime99 picture digime99  路  5Comments

mhagesfeld picture mhagesfeld  路  3Comments

ivivanov picture ivivanov  路  3Comments

eat-sleep-code picture eat-sleep-code  路  3Comments