Created
February 18, 2013 15:44
-
-
Save CoreyKaylor/4978316 to your computer and use it in GitHub Desktop.
Gimped sample of sending an email with fubu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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