惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
G
Google Developers Blog
博客园 - 三生石上(FineUI控件)
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
V
V2EX
Vercel News
Vercel News
U
Unit 42
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
J
Java Code Geeks
WordPress大学
WordPress大学
罗磊的独立博客
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
M
MIT News - Artificial intelligence
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Apple Machine Learning Research
Apple Machine Learning Research
Martin Fowler
Martin Fowler
云风的 BLOG
云风的 BLOG

博客园 - 绿叶

Suspicions about the new platform dynamic sorting expression builder How to create your own api with ACL in Magento 台服信长之野望全后台辅助外挂 SEO Elite ver 4.0 R93 Patcher Remove 5 seconds constraint in Garena(GGC) - 绿叶 Robot development framework in Mush Client (Lua) 巧用Marshal.GetDelegateForFunctionPointer--C#如何调用按键精灵插件dll Using .Net, Flex, and Red5 to create a flash web application 做了个C#的Hotkey简单封装,希望对大家有帮助 功夫世界外挂发布测试 我的第一个全后台CALL外挂-功夫世界外挂 通过修改Mutex来达到大航海OL多开 如何利用WPE对大航海Online进行港内瞬移,瞬时生产和快速进港 MonoRail PetShop Source Code Released MS PetShop3 -> MonoRail PetShop 完成移植 移植MSPetShop3到Castle MonoRail -Model与DAL层的移植(AR) 对 "闭包-closure" 的一些见解 圈内Castle文章索引
利用Castle Framework发email是如此easy
绿叶 · 2006-03-08 · via 博客园 - 绿叶

        最近要在项目中发送对用户发送各种各样的邀请函,项目是使用castle作为框架的。发现castle中的一个Component(email sender)是封装了System.Web.Mail,而framework再对这个Component封装,从而使他email支持模板,废话少说,看具体用法吧:

配置:
        1.在web.config中的配置smtp的几个简单参数:

<monoRail smtpHost="host name" smtpUsername="username" smtpPassword="password">
.
</monoRail>

        2.在views目录下建个mail目录,放email模板,比如:(invitation.vm)

from:$from
to:$to
subject:$subject
<html>
<head>
<title>邀请函</title>
</head>
<body>
$name 邀请你XXXXX
</body>
</html>

        3.先用PropertyBag.Add模板的的参数,比如:PropertyBag.Add("from", "wjshome#gmail.com")

        4.使用RenderMailMessage("invitation")函数获取一个Message对象
这里你可以更改他的encording,中文可以设置成"gb2312"。
还可以更改message的format,做format时,框架已经自动帮你处理了,如果检测到模板中包含<html>,则自动把format设置成html格式。

        5.用DeliverEmail(message)发送。

        6.如果你不用设置Message对象的参数的话,你可以直接用RenderEmailAndSend("invitaion")替代第4.5步。

呵呵~完了,简单吧,有兴趣的去试试~~