質問編集履歴
1
「MailStuffタブ」のオリジナルソースを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -127,3 +127,119 @@
|
|
127
127
|
上記の方法は画像を送信する物のようですが、出来れば上がれば次にテキストのみの送信テストを行いたいと考えておりますが、「この方法よりもっと簡単な方法がある」などのご意見もふまえた上で、ご知恵をお借りできればと思います。
|
128
128
|
|
129
129
|
宜しくお願いいたします。
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
**追記**
|
134
|
+
|
135
|
+
ご指摘のあった「MailStuffタブ」のソースを追記します。
|
136
|
+
|
137
|
+
```ここに言語を入力
|
138
|
+
|
139
|
+
// Example functions that send mail (smtp)
|
140
|
+
|
141
|
+
// You can also do imap, but that's not included here
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
// A function to check a mail account
|
146
|
+
|
147
|
+
import java.util.*;
|
148
|
+
|
149
|
+
import java.io.*;
|
150
|
+
|
151
|
+
import javax.activation.*;
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
// A function to send mail
|
156
|
+
|
157
|
+
void sendMail() {
|
158
|
+
|
159
|
+
// Create a session
|
160
|
+
|
161
|
+
String host="smtp.gmail.com";
|
162
|
+
|
163
|
+
Properties props=new Properties();
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
// SMTP Session
|
168
|
+
|
169
|
+
props.put("mail.transport.protocol", "smtp");
|
170
|
+
|
171
|
+
props.put("mail.smtp.host", host);
|
172
|
+
|
173
|
+
props.put("mail.smtp.port", "587");
|
174
|
+
|
175
|
+
props.put("mail.smtp.auth", "true");
|
176
|
+
|
177
|
+
// We need TTLS, which gmail requires
|
178
|
+
|
179
|
+
props.put("mail.smtp.starttls.enable","true");
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
// Create a session
|
184
|
+
|
185
|
+
Session session = Session.getDefaultInstance(props, new Auth());
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
try
|
190
|
+
|
191
|
+
{
|
192
|
+
|
193
|
+
MimeMessage msg=new MimeMessage(session);
|
194
|
+
|
195
|
+
msg.setFrom(new InternetAddress("someone@example.com", "Name"));
|
196
|
+
|
197
|
+
msg.addRecipient(Message.RecipientType.TO,new InternetAddress("recipient@example.com"));
|
198
|
+
|
199
|
+
msg.setSubject("Email with Processing");
|
200
|
+
|
201
|
+
BodyPart messageBodyPart = new MimeBodyPart();
|
202
|
+
|
203
|
+
// Fill the message
|
204
|
+
|
205
|
+
messageBodyPart.setText("Email sent with Processing");
|
206
|
+
|
207
|
+
Multipart multipart = new MimeMultipart();
|
208
|
+
|
209
|
+
multipart.addBodyPart(messageBodyPart);
|
210
|
+
|
211
|
+
// Part two is attachment
|
212
|
+
|
213
|
+
messageBodyPart = new MimeBodyPart();
|
214
|
+
|
215
|
+
DataSource source = new FileDataSource("c:\\image.jpg");
|
216
|
+
|
217
|
+
messageBodyPart.setDataHandler(new DataHandler(source));
|
218
|
+
|
219
|
+
messageBodyPart.setFileName("image.jpg");
|
220
|
+
|
221
|
+
multipart.addBodyPart(messageBodyPart);
|
222
|
+
|
223
|
+
msg.setContent(multipart);
|
224
|
+
|
225
|
+
msg.setSentDate(new Date());
|
226
|
+
|
227
|
+
Transport.send(msg);
|
228
|
+
|
229
|
+
println("Mail sent!");
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
catch(Exception e)
|
234
|
+
|
235
|
+
{
|
236
|
+
|
237
|
+
e.printStackTrace();
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
```
|