Minor changes to improve testability of helpers
[castle.git] / MonoRail / Castle.MonoRail.Framework / Services / MonoRailSmtpSender.cs
blob489f6ca6a989c34bbe2da95bd3f02cc89553f13b
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Services
17 using System;
18 using Castle.Components.Common.EmailSender;
19 using Castle.Components.Common.EmailSender.Smtp;
20 using Castle.Core;
21 using Castle.MonoRail.Framework.Configuration;
23 /// <summary>
24 /// MonoRail internal email sender service
25 /// </summary>
26 public class MonoRailSmtpSender : IEmailSender, IServiceEnabledComponent
28 private SmtpSender sender;
30 /// <summary>
31 /// Initializes a new instance of the <see cref="MonoRailSmtpSender"/> class.
32 /// </summary>
33 public MonoRailSmtpSender()
37 #region IServiceEnabledComponent implementation
39 /// <summary>
40 /// Services the specified provider.
41 /// </summary>
42 /// <param name="provider">The provider.</param>
43 public void Service(IServiceProvider provider)
45 MonoRailConfiguration config = (MonoRailConfiguration) provider.GetService(typeof(MonoRailConfiguration));
47 sender = new SmtpSender(config.SmtpConfig.Host);
48 sender.Port = config.SmtpConfig.Port;
50 if (config.SmtpConfig.Username != null && config.SmtpConfig.Username != String.Empty)
52 sender.UserName = config.SmtpConfig.Username;
54 if (config.SmtpConfig.Password != null && config.SmtpConfig.Password != String.Empty)
56 sender.Password = config.SmtpConfig.Password;
60 #endregion
62 /// <summary>
63 /// Sends a message.
64 /// </summary>
65 /// <param name="from">From field</param>
66 /// <param name="to">To field</param>
67 /// <param name="subject">e-mail's subject</param>
68 /// <param name="messageText">message's body</param>
69 public void Send(string from, string to, string subject, string messageText)
71 sender.Send(from, to, subject, messageText);
74 /// <summary>
75 /// Sends a message.
76 /// </summary>
77 /// <param name="message">Message instance</param>
78 public void Send(Message message)
80 sender.Send(message);
83 /// <summary>
84 /// Sends multiple messages.
85 /// </summary>
86 /// <param name="messages">Array of messages</param>
87 public void Send(Message[] messages)
89 sender.Send(messages);