SlideShare a Scribd company logo
1 of 8
MvcMailer
By Jax
Scaffold Your Mailer
PM> Scaffold Mailer.Razor UserMailer Welcome,PasswordReset
•
•
•
•
•

MailersIUserMailer.cs
MailersUserMailer.cs
ViewsUserMailer_Layout.cshtml
ViewsUserMailerWelcome.cshtml
ViewsUserMailerPasswordReset.cshtml
Pass Data to Mailer Views
ViewBag.Name = "Sohan";
ViewBag.Comment = myComment;
ViewData["Name"] = "Sohan";
ViewData["Comment"] = myComment;
var comment = new Comment { To = you, Message = "Great Work!" };
ViewData = new ViewDataDictionary(comment);
var comment = new Comment { To = you, Message = "Great Work!" };
ViewData.Model = comment;
Send
var userMailer = new UserMailer();
userMailer.Welcome().Send();
userMailer.Welcome().SendAsync();
Other Options
# No Interface
PM> Scaffold Mailer.Razor MyMailer Welcome -NoInterface
# This will produce Razor views
PM> Scaffold Mailer.Razor UserMailer Welcome,GoodBye
# This will produce Aspx views
PM> Scaffold Mailer.Aspx UserMailer Welcome,GoodBye
Send Multi-part Emails
PM> scaffold Mailer MyMailer Hello –WithText
•
•
•
•
•
•

MailersIMyMailer.cs
MailersMyMailer.cs
ViewsMyMailer_Layout.cshtml
ViewsMyMailerHello.cshtml
ViewsMyMailer_Layout.text.cshtml
ViewsMyMailerHello.text.cshtml
Embed Image or Linked Resource Inside Email
In Your View
@using Mvc.Mailer
@Html.InlineImage("logo", "Company Logo")
### public static IHtmlString InlineImage(this HtmlHelper htmlHelper, string contentId, string alt = "");

In Your Mailer
var resources = new Dictionary<string, string>();
resources["logo"] = @"D:001.png";
PopulateBody(mailMessage, "WelcomeMessage", resources);
My Using
private MvcMailMessage getMailMessage(string viewName, object vm = null)
{
ViewData.Model = vm;
MvcMailMessage message = Populate(x => { x.ViewName = viewName; });
message.Subject = Regex.Match(
message.Body,
@"(?<=<title[^>]*>)([^<]*)(?=</title>)",
RegexOptions.IgnoreCase
).Value.Trim();
return message;
}
public virtual MvcMailMessage MemberEnabledNotice(MemberViewModel vm)
{
MvcMailMessage message = getMailMessage("MemberEnabledNotice", vm);
/*To Member*/
message.To.Add(vm.Email);
return message;
}

More Related Content

Similar to Mvc Mailer

Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
Jay Shirley
 

Similar to Mvc Mailer (10)

PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
Make Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingMake Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance Testing
 
Training in Asp.net mvc3 platform-apextgi,noida
Training in Asp.net mvc3 platform-apextgi,noidaTraining in Asp.net mvc3 platform-apextgi,noida
Training in Asp.net mvc3 platform-apextgi,noida
 
Rest with grails 3
Rest with grails 3Rest with grails 3
Rest with grails 3
 
PHP記帳網頁教材(第一頁是空白的)
PHP記帳網頁教材(第一頁是空白的)PHP記帳網頁教材(第一頁是空白的)
PHP記帳網頁教材(第一頁是空白的)
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone Interactivity
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
 
PHP with MYSQL
PHP with MYSQLPHP with MYSQL
PHP with MYSQL
 
Microsoft Web Matrix
Microsoft Web MatrixMicrosoft Web Matrix
Microsoft Web Matrix
 
WebSockets Jump Start
WebSockets Jump StartWebSockets Jump Start
WebSockets Jump Start
 

More from LearningTech (20)

vim
vimvim
vim
 
PostCss
PostCssPostCss
PostCss
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection &amp; activator
Reflection &amp; activatorReflection &amp; activator
Reflection &amp; activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

Mvc Mailer

  • 2. Scaffold Your Mailer PM> Scaffold Mailer.Razor UserMailer Welcome,PasswordReset • • • • • MailersIUserMailer.cs MailersUserMailer.cs ViewsUserMailer_Layout.cshtml ViewsUserMailerWelcome.cshtml ViewsUserMailerPasswordReset.cshtml
  • 3. Pass Data to Mailer Views ViewBag.Name = "Sohan"; ViewBag.Comment = myComment; ViewData["Name"] = "Sohan"; ViewData["Comment"] = myComment; var comment = new Comment { To = you, Message = "Great Work!" }; ViewData = new ViewDataDictionary(comment); var comment = new Comment { To = you, Message = "Great Work!" }; ViewData.Model = comment;
  • 4. Send var userMailer = new UserMailer(); userMailer.Welcome().Send(); userMailer.Welcome().SendAsync();
  • 5. Other Options # No Interface PM> Scaffold Mailer.Razor MyMailer Welcome -NoInterface # This will produce Razor views PM> Scaffold Mailer.Razor UserMailer Welcome,GoodBye # This will produce Aspx views PM> Scaffold Mailer.Aspx UserMailer Welcome,GoodBye
  • 6. Send Multi-part Emails PM> scaffold Mailer MyMailer Hello –WithText • • • • • • MailersIMyMailer.cs MailersMyMailer.cs ViewsMyMailer_Layout.cshtml ViewsMyMailerHello.cshtml ViewsMyMailer_Layout.text.cshtml ViewsMyMailerHello.text.cshtml
  • 7. Embed Image or Linked Resource Inside Email In Your View @using Mvc.Mailer @Html.InlineImage("logo", "Company Logo") ### public static IHtmlString InlineImage(this HtmlHelper htmlHelper, string contentId, string alt = ""); In Your Mailer var resources = new Dictionary<string, string>(); resources["logo"] = @"D:001.png"; PopulateBody(mailMessage, "WelcomeMessage", resources);
  • 8. My Using private MvcMailMessage getMailMessage(string viewName, object vm = null) { ViewData.Model = vm; MvcMailMessage message = Populate(x => { x.ViewName = viewName; }); message.Subject = Regex.Match( message.Body, @"(?<=<title[^>]*>)([^<]*)(?=</title>)", RegexOptions.IgnoreCase ).Value.Trim(); return message; } public virtual MvcMailMessage MemberEnabledNotice(MemberViewModel vm) { MvcMailMessage message = getMailMessage("MemberEnabledNotice", vm); /*To Member*/ message.To.Add(vm.Email); return message; }