bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / runner / helper / SimpleMailSender.java
blobecdcf214a0a79c39acdaeeb28985220e0b55ba25
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package helper;
20 import java.io.BufferedReader;
21 import java.io.BufferedWriter;
22 import java.io.InputStreamReader;
23 import java.io.OutputStreamWriter;
25 import java.net.InetAddress;
26 import java.net.Socket;
27 import java.net.UnknownHostException;
30 public class SimpleMailSender {
31 private String m_MailServer = "unknown";
32 private String m_Sender = "unknown";
33 private String m_Recipient = "unknown";
34 private String m_Subject = "unknown";
35 private String m_Message = "unknown";
38 public String getMailServer() {
39 return m_MailServer;
42 public void setMailServer(String server) {
43 m_MailServer = server;
46 public String getSender() {
47 return m_Sender;
50 public void setSender(String sender) {
51 m_Sender = sender;
54 public String getRecipient() {
55 return m_Recipient;
58 public void setRecipient(String recipient) {
59 m_Recipient = recipient;
62 public String getSubject() {
63 return m_Subject;
66 public void setSubject(String subject) {
67 m_Subject = subject;
70 public String getMessage() {
71 return m_Message;
74 public void setMessage(String msg) {
75 m_Message = msg;
78 public void sendMail() {
79 if (m_MailServer.equals ("unknown")) {
80 System.out.println("No Mailserver given ... exiting");
81 return;
83 if (m_Recipient.equals ("unknown")) {
84 System.out.println("No Recipient given ... exiting");
85 return;
87 sendMail(m_MailServer,m_Sender,m_Recipient,m_Subject,m_Message);
90 public void sendMail(String server, String sender,
91 String recipient, String subject, String msg) {
92 //setting member variables for reuse
93 m_MailServer = server;
94 m_Sender = sender;
95 m_Recipient = recipient;
96 m_Subject = subject;
97 m_Message = msg;
99 try {
100 Socket socket = new Socket(m_MailServer, 25);
101 BufferedReader input =
102 new BufferedReader(new InputStreamReader(
103 socket.getInputStream(), "8859_1"));
104 BufferedWriter output =
105 new BufferedWriter(new OutputStreamWriter(
106 socket.getOutputStream(), "8859_1"));
108 sendline(input, output, "HELO " + getHostName());
109 sendline(input, output, "MAIL FROM: " + m_Sender);
110 sendline(input, output, "RCPT TO: <" + m_Recipient + ">");
111 sendline(input, output, "DATA");
112 sendline(output, "MIME-Version: 1.0");
113 sendline(output, "Subject: " + m_Subject);
114 sendline(output, "From: " + m_Sender);
115 sendline(output, "To: " + m_Recipient);
116 sendline(output,
117 "Content-Type: text/html; charset=\"us-ascii\"\r\n");
119 // Send the body
120 sendline(output, m_Message);
122 sendline(input, output, ".");
123 sendline(input, output, "QUIT");
124 socket.close();
125 } catch (Exception e) {
126 e.printStackTrace();
130 private void sendline(BufferedReader input,
131 BufferedWriter output, String line) {
132 try {
133 output.write(line + "\r\n");
134 output.flush();
135 line = input.readLine();
136 } catch (Exception e) {
137 e.printStackTrace();
141 private void sendline(BufferedWriter output, String line) {
142 try {
143 output.write(line + "\r\n");
144 output.flush();
145 } catch (Exception e) {
146 e.printStackTrace();
150 private String getHostName() {
151 String hostname = "";
153 try {
154 InetAddress addr = InetAddress.getLocalHost();
156 hostname = addr.getHostName();
157 } catch (UnknownHostException e) {
160 return hostname;