View | Details | Raw Unified | Return to bug 19125
Collapse All | Expand All

(-)src/java/org/apache/log4j/net/SMTPAppender.java (-34 / +100 lines)
Lines 43-52 Link Here
43
   @author Ceki Gülcü
43
   @author Ceki Gülcü
44
   @since 1.0 */
44
   @since 1.0 */
45
public class SMTPAppender extends AppenderSkeleton {
45
public class SMTPAppender extends AppenderSkeleton {
46
  /**
47
   * Comma seperated list of email addresses for the To line.
48
   */
46
  private String to;
49
  private String to;
50
  /**
51
   * Comma seperated list of email addresses for the Cc line.
52
   */
53
  private String cc;
54
  /**
55
   * Email addresses for the From line (also becomes the reply-to).
56
   */
47
  private String from;
57
  private String from;
58
  /**
59
   * Email subject line value.
60
   */
48
  private String subject;
61
  private String subject;
62
  /**
63
   * Email server to use to send messages.
64
   */
49
  private String smtpHost;
65
  private String smtpHost;
66
67
  /**
68
   * Email header used to set messages to higher or lower priority given a numerical value of 1 through 5.
69
   * <ol>
70
   *	<li>Highest Priority</li>
71
   *	<li>High Priority</li>
72
   *	<li>Normal (default if not defined)</li>
73
   *	<li>Low Priority</li>
74
   *	<li>Lowest Priority</li>
75
   * </ol>
76
   */
77
  private int priority = 3;
50
  private int bufferSize = 512;
78
  private int bufferSize = 512;
51
  private boolean locationInfo = false;
79
  private boolean locationInfo = false;
52
80
Lines 92-106 Link Here
92
120
93
     try {
121
     try {
94
       if (from != null)
122
       if (from != null)
95
	 msg.setFrom(getAddress(from));
123
	 	msg.setFrom(getAddress(from));
96
       else
124
       else
97
	 msg.setFrom();
125
	 	msg.setFrom();
98
126
99
       msg.setRecipients(Message.RecipientType.TO, parseAddress(to));
127
       msg.setRecipients(Message.RecipientType.TO, parseAddress(to));
128
129
	   	//Add CC receipients if defined.
130
       if (cc != null && !"".equals(cc)) {
131
       		msg.setRecipients(Message.RecipientType.CC, parseAddress(cc));
132
       }
133
134
       //Set email priority
135
       msg.addHeader("X-Priority", String.valueOf(getPriority()));
136
137
		//Add Subject if present
100
       if(subject != null)
138
       if(subject != null)
101
	 msg.setSubject(subject);
139
	 	msg.setSubject(subject);
102
     } catch(MessagingException e) {
140
     } catch(MessagingException e) {
103
       LogLog.error("Could not activate SMTPAppender options.", e );
141
       	LogLog.error("Could not activate SMTPAppender options.", e );
104
     }
142
     }
105
  }
143
  }
106
144
Lines 180-193 Link Here
180
    }
218
    }
181
  }
219
  }
182
220
183
  /**
184
     Returns value of the <b>To</b> option.
185
   */
186
  public
187
  String getTo() {
188
    return to;
189
  }
190
191
221
192
  /**
222
  /**
193
     The <code>SMTPAppender</code> requires a {@link
223
     The <code>SMTPAppender</code> requires a {@link
Lines 242-248 Link Here
242
    }
272
    }
243
  }
273
  }
244
274
245
275
  /**
276
     The <b>EvaluatorClass</b> option takes a string value
277
     representing the name of the class implementing the {@link
278
     TriggeringEventEvaluator} interface. A corresponding object will
279
     be instantiated and assigned as the triggering event evaluator
280
     for the SMTPAppender.
281
   */
282
  public
283
  void setEvaluatorClass(String value) {
284
      evaluator = (TriggeringEventEvaluator)
285
                OptionConverter.instantiateByClassName(value,
286
					   TriggeringEventEvaluator.class,
287
						       evaluator);
288
  }
246
289
247
  /**
290
  /**
248
     Returns value of the <b>EvaluatorClass</b> option.
291
     Returns value of the <b>EvaluatorClass</b> option.
Lines 253-263 Link Here
253
  }
296
  }
254
297
255
  /**
298
  /**
256
     Returns value of the <b>From</b> option.
299
     The <b>Subject</b> option takes a string value which should be a
300
     the subject of the e-mail message.
257
   */
301
   */
258
  public
302
  public
259
  String getFrom() {
303
  void setSubject(String subject) {
260
    return from;
304
    this.subject = subject;
261
  }
305
  }
262
306
263
  /**
307
  /**
Lines 278-292 Link Here
278
  }
322
  }
279
323
280
  /**
324
  /**
281
     The <b>Subject</b> option takes a string value which should be a
325
     Returns value of the <b>From</b> option.
282
     the subject of the e-mail message.
283
   */
326
   */
284
  public
327
  public
285
  void setSubject(String subject) {
328
  String getFrom() {
286
    this.subject = subject;
329
    return from;
287
  }
330
  }
288
331
289
290
  /**
332
  /**
291
     The <b>BufferSize</b> option takes a positive integer
333
     The <b>BufferSize</b> option takes a positive integer
292
     representing the maximum number of logging events to collect in a
334
     representing the maximum number of logging events to collect in a
Lines 301-306 Link Here
301
  }
343
  }
302
344
303
  /**
345
  /**
346
     Returns value of the <b>BufferSize</b> option.
347
   */
348
  public
349
  int getBufferSize() {
350
    return bufferSize;
351
  }
352
353
  /**
304
     The <b>SMTPHost</b> option takes a string value which should be a
354
     The <b>SMTPHost</b> option takes a string value which should be a
305
     the host name of the SMTP server that will send the e-mail message.
355
     the host name of the SMTP server that will send the e-mail message.
306
   */
356
   */
Lines 326-356 Link Here
326
    this.to = to;
376
    this.to = to;
327
  }
377
  }
328
378
379
  /**
380
     Returns value of the <b>To</b> option.
381
   */
382
  public
383
  String getTo() {
384
    return to;
385
  }
329
386
387
  /**
388
     The <b>Cc</b> option takes a string value which should be a
389
     comma separated list of e-mail address of the recipients.
390
   */
391
  public
392
  void setCc(String cc) {
393
    this.cc = cc;
394
  }
330
395
331
  /**
396
  /**
332
     Returns value of the <b>BufferSize</b> option.
397
     Returns value of the <b>Cc</b> option.
333
   */
398
   */
334
  public
399
  public
335
  int getBufferSize() {
400
  String getCc() {
336
    return bufferSize;
401
    return cc;
337
  }
402
  }
338
403
339
  /**
404
  /**
340
     The <b>EvaluatorClass</b> option takes a string value
405
     The <b>Priority</b> option takes a positive integer (1 through 5)
341
     representing the name of the class implementing the {@link
406
     representing the priority of the email message.  Default is 3 (aka normal).
342
     TriggeringEventEvaluator} interface. A corresponding object will
343
     be instantiated and assigned as the triggering event evaluator
344
     for the SMTPAppender.
345
   */
407
   */
346
  public
408
  public
347
  void setEvaluatorClass(String value) {
409
  void setPriority(int priority) {
348
      evaluator = (TriggeringEventEvaluator)
410
    this.priority = priority;
349
                OptionConverter.instantiateByClassName(value,
350
					   TriggeringEventEvaluator.class,
351
						       evaluator);
352
  }
411
  }
353
412
413
  /**
414
     Returns value of the <b>Priority</b> option.
415
   */
416
  public
417
  int getPriority() {
418
    return priority;
419
  }
354
420
355
  /**
421
  /**
356
     The <b>LocationInfo</b> option takes a boolean value. By
422
     The <b>LocationInfo</b> option takes a boolean value. By

Return to bug 19125