public Message createMessage(List<String> toAddresses) {\r
MimeMessage message = new MimeMessage(session);\r
try {\r
- InternetAddress from = new InternetAddress(settings.getString(Keys.mail.fromAddress,\r
- "gitblit@gitblit.com"), "Gitblit");\r
+ String fromAddress = settings.getString(Keys.mail.fromAddress, null);\r
+ if (StringUtils.isEmpty(fromAddress)) {\r
+ fromAddress = "gitblit@gitblit.com";\r
+ }\r
+ InternetAddress from = new InternetAddress(fromAddress, "Gitblit");\r
message.setFrom(from);\r
\r
InternetAddress[] tos = new InternetAddress[toAddresses.size()];\r
return message;\r
}\r
\r
+ /**\r
+ * Returns the status of the mail queue.\r
+ * \r
+ * @return true, if the queue is empty\r
+ */\r
+ public boolean hasEmptyQueue() {\r
+ return queue.isEmpty();\r
+ }\r
+\r
/**\r
* Queue's an email message to be sent.\r
* \r
--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.tests;\r
+\r
+import javax.mail.Message;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import com.gitblit.FileSettings;\r
+import com.gitblit.MailExecutor;\r
+\r
+public class MailTest extends TestCase {\r
+\r
+ public void testSendMail() throws Exception {\r
+ FileSettings settings = new FileSettings("mailtest.properties");\r
+ MailExecutor mail = new MailExecutor(settings);\r
+ Message message = mail.createMessageForAdministrators();\r
+ message.setSubject("Test");\r
+ message.setText("this is a test");\r
+ mail.queue(message);\r
+ mail.run(); \r
+\r
+ assertTrue("mail queue is not empty!", mail.hasEmptyQueue());\r
+ }\r
+}\r