1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using Castle
.Components
.Common
.EmailSender
;
19 using Castle
.Components
.Common
.EmailSender
.Smtp
;
21 using Castle
.MonoRail
.Framework
.Configuration
;
24 /// MonoRail internal email sender service
26 public class MonoRailSmtpSender
: IEmailSender
, IServiceEnabledComponent
28 private SmtpSender sender
;
31 /// Initializes a new instance of the <see cref="MonoRailSmtpSender"/> class.
33 public MonoRailSmtpSender()
37 #region IServiceEnabledComponent implementation
40 /// Services the specified provider.
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
;
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
);
77 /// <param name="message">Message instance</param>
78 public void Send(Message message
)
84 /// Sends multiple messages.
86 /// <param name="messages">Array of messages</param>
87 public void Send(Message
[] messages
)
89 sender
.Send(messages
);