GithubHelp home page GithubHelp logo

east-sussex-county-council / escc.azureemailforwarder Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 2.0 490 KB

Send emails from Windows Azure using an Azure queue and an on-premise SMTP server

License: Other

C# 88.07% Batchfile 0.37% CSS 1.13% JavaScript 10.43%

escc.azureemailforwarder's Introduction

Escc.AzureEmailForwarder

Windows Azure does not have a built-in SMTP service. One option is to serialise emails to Azure storage, and have an on-premise application watch the queue and send the emails using your existing SMTP server as described on the Microsoft Azure blog.

The queuing code is adapted from the Azure Friday series on queuing (4 episodes) by Scott Hanselman and Mark Simms.

When you send an email using AzureQueuedEmailSender it serialises the email to a blob (to avoid any size limit for attachments), then stores the URL of the blob in a queue. This application runs on-premise with access to your own SMTP server. It watches the queue and either forwards emails and deletes them from the storage account or, if it fails for some reason, it moves the URL to table storage for manual processing, so that it does not keep reappearing on the queue or eventually expire from it.

We use Exe2Srv to run this application as a Windows Service. Exe2Srv and example configuration files are included in the Exe2Srv folder.

We use Log4Net and Exceptionless for logging and error reporting, but you can substitute any ILogger implementation.

C#

In this example configuration settings come from web.config or app.config, but they could come from any IServiceRegistry. The ASP.NET application cache is being used to avoid recreating the email service, but this could be any IServiceCacheStrategy or none.

var email = new MailMessage("[email protected]", "[email protected]", "subject", "body");
var configuration = new ConfigurationServiceRegistry();
var cache = new HttpContextCacheStrategy();

var emailService = ServiceContainer<IEmailSender>.LoadService(configuration, cache);

emailService.Send(email); 

web.config for sending email

<configuration>
  <configSections>
    <sectionGroup name="Escc.Services">
      <section name="ServiceRegistry" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    </sectionGroup>
  </configSections>
  
  <Escc.Services>
    <ServiceRegistry>
      <add key="Escc.Services.IEmailSender" value="Escc.Services.Azure.AzureQueuedEmailSender, Escc.Services.Azure" />
    </ServiceRegistry>
  </Escc.Services>

  <connectionStrings>
    <add name="Escc.Services.Azure.EmailQueue" connectionString="UseDevelopmentStorage=true"/>
  </connectionStrings>
</configuration>

For app.config for Escc.AzureEmailForwarder, see app.example.config.

Escc.AzureEmailForwarder.Monitor

This .NET Core web application lets you monitor the blobs in the storage account. This is useful when there is a problem and emails fail to send. You can view and send the failed emails, or delete the blob if the email is no longer relevant.

The application is a first draft and lacks user security, so it should only deployed if security is configured at the web server level. It also lacks management of the badmail table, looking instead directly at blob storage. This means that:

  • you need manually to check the date of the email as, if it's very recent, it may still be about to be processed automatically
  • if you click 'send' or 'delete', the blob is deleted but the corresponding record in the badmail table needs to be deleted manually

escc.azureemailforwarder's People

Contributors

wolfkhan66 avatar

Watchers

 avatar  avatar  avatar  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.