メイン コンテンツにスキップ

 Subscribe

Editor’s Note:  Today’s post comes from Gabe Moothart, Software Engineer at SendGrid. SendGrid provides businesses with a cloud-based email service, relieving businesses of the cost and complexity of maintaining custom email systems.

Did you know that as a Windows Azure customer, you can easily access a highly scalable email delivery solution that integrates into applications on any Windows Azure environment? Getting started with SendGrid on Windows Azure is easy.

The first thing you’ll need is a SendGrid account. You can find SendGrid in the Windows Azure Marketplace here. Just click the green “Learn More” button and continue through the signup process to create a SendGrid account.  As a Windows Azure customer, you are automatically given a free package to send up to 25,000 emails/month.

And then “Sign up Now” to create your SendGrid account.

 

Now that your SendGrid account has been created, it’s time to integrate it into a Windows Azure Web Site. Login and click the “+ New” button at the bottom of the page to create a new Web Site:

After the website has been created, select it in the management portal and find the “Web Matrix” button at the bottom of the page. This will open your new website in WebMatrix, installing it if necessary. WebMatrix will alert you that your site is empty:

 

Choose “Yes, install from the template Gallery” and select the “Empty Site” template.

Choose the “Files” view on the left-hand side, and then from the File menu, select “New” -> “File”, and choose the “Web.Config (4.0)” file type.

 

Next, we need to tell Asp.Net to use the SendGrid SMTP server. Add this text to the new Web config, inside the <configuration> tag:

<system.net>
    <mailSettings>
        <smtp>
            <network host=”smtp.sendgrid.com” userName=”sendgrid username”
password=”sendgrid password” />
        smtp>
    mailSettings>
system.net>

Make sure to insert your own SendGrid username and password. Next open the Default.cshtml file. Add this markup inside the <body> tag:

<h1>Sendgrid Demo</h1>
<form method=”post”>
    <div>
        <p>@message</p>
        <p>nput type=”submit” value=”Send Email” /></p>
    div>
form>

And finally, add the code to actually send the email via SendGrid to the top of the Default.cshtml file:

@{
   string message = “”;
    if (IsPost) {
        var c = new System.Net.Mail.SmtpClient();
        c.Send(“from@domain.com”, “to@domain.com”, “subject”, “body”);
        message = “Email sent!!”;   
    }
}

Change “from@domain.com” to your email address, “to@domain.com” to the email address you are sending to, and edit the “subject” and “body” parameters to your desired content.

All that’s left is to click “Publish” to push your changes back to Windows Azure, and to browse to the site. Clicking “Send Email” will cause the email to be sent.

That’s it! With SendGrid, developers like you can focus on building better systems and earning more revenue, while reducing costs in engineering and infrastructure management. Go build the next big application. Let SendGrid take care of your email. 

  • Explore

     

    Let us know what you think of Azure and what you would like to see in the future.

     

    Provide feedback

  • Build your cloud computing and Azure skills with free courses by Microsoft Learn.

     

    Explore Azure learning


Join the conversation