Skip to content

Instantly share code, notes, and snippets.

@CoreyKaylor
Created February 18, 2013 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CoreyKaylor/4978316 to your computer and use it in GitHub Desktop.
Save CoreyKaylor/4978316 to your computer and use it in GitHub Desktop.
Gimped sample of sending an email with fubu
public class SendEmailNowBehavior<TResponse> : IActionBehavior
where TResponse : RenderEmailBase
{
private readonly IOutputWriter _outputWriter;
private readonly IFubuRequest _fubuRequest;
private readonly IMailer _mailer;
public SendEmailNowBehavior(IOutputWriter outputWriter, IFubuRequest fubuRequest, IMailer mailer)
{
_outputWriter = outputWriter;
_fubuRequest = fubuRequest;
_mailer = mailer;
}
public IActionBehavior InsideBehavior { get; set; }
public void Invoke()
{
if(InsideBehavior == null)
throw new InvalidOperationException("To send the email there must be an output behavior to render the spark view.");
_fubuRequest.Set(new CurrentMimeType("*/*", "text/html"));
var response = _fubuRequest.Get<TResponse>();
if (response == null)
return;
response.Body = _outputWriter.Record(() => InsideBehavior.Invoke()).GetText();
_mailer.SendEmail(response.Subject, response.ToEmailAddress, response.Body);
}
public void InvokePartial()
{
throw new System.NotImplementedException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment