parent
f0d4c51ef6
commit
a85de95c0b
1 changed files with 129 additions and 79 deletions
|
@ -177,7 +177,8 @@ public class MailObject extends ScriptableObject implements Serializable {
|
|||
* @throws Exception ...
|
||||
* @throws IOException ...
|
||||
*/
|
||||
public void addPart(Object obj, Object filename) throws Exception {
|
||||
public void addPart(Object obj, Object filename) {
|
||||
try {
|
||||
if (obj == null || obj == Undefined.instance) {
|
||||
throw new IOException("mail.addPart called with wrong number of arguments.");
|
||||
}
|
||||
|
@ -210,6 +211,11 @@ public class MailObject extends ScriptableObject implements Serializable {
|
|||
}
|
||||
|
||||
multipart.addBodyPart(part);
|
||||
} catch (Exception mx) {
|
||||
System.err.println("Error in MailObject.addPart(): "+mx);
|
||||
setStatus(MIMEPART);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -219,12 +225,17 @@ public class MailObject extends ScriptableObject implements Serializable {
|
|||
*
|
||||
* @throws Exception ...
|
||||
*/
|
||||
public void setSubject(Object subject) throws Exception {
|
||||
public void setSubject(Object subject) {
|
||||
if (subject == null || subject == Undefined.instance) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
message.setSubject(MimeUtility.encodeWord(subject.toString()));
|
||||
} catch (Exception mx) {
|
||||
System.err.println("Error in MailObject.setSubject(): "+mx);
|
||||
setStatus(SUBJECT);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -235,7 +246,8 @@ public class MailObject extends ScriptableObject implements Serializable {
|
|||
* @throws Exception ...
|
||||
* @throws AddressException ...
|
||||
*/
|
||||
public void setReplyTo(String addstr) throws Exception {
|
||||
public void setReplyTo(String addstr) {
|
||||
try {
|
||||
if (addstr.indexOf("@") < 0) {
|
||||
throw new AddressException();
|
||||
}
|
||||
|
@ -244,6 +256,10 @@ public class MailObject extends ScriptableObject implements Serializable {
|
|||
|
||||
replyTo[0] = new InternetAddress(addstr);
|
||||
message.setReplyTo(replyTo);
|
||||
} catch (Exception mx) {
|
||||
System.err.println("Error in MailObject.setReplyTo(): "+mx);
|
||||
setStatus(REPLYTO);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -255,7 +271,8 @@ public class MailObject extends ScriptableObject implements Serializable {
|
|||
* @throws Exception ...
|
||||
* @throws AddressException ...
|
||||
*/
|
||||
public void setFrom(String addstr, Object name) throws Exception {
|
||||
public void setFrom(String addstr, Object name) {
|
||||
try {
|
||||
if (addstr.indexOf("@") < 0) {
|
||||
throw new AddressException();
|
||||
}
|
||||
|
@ -270,6 +287,10 @@ public class MailObject extends ScriptableObject implements Serializable {
|
|||
}
|
||||
|
||||
message.setFrom(address);
|
||||
} catch (Exception mx) {
|
||||
System.err.println("Error in MailObject.setFrom(): "+mx);
|
||||
setStatus(FROM);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -282,8 +303,14 @@ public class MailObject extends ScriptableObject implements Serializable {
|
|||
* @throws Exception ...
|
||||
* @throws AddressException ...
|
||||
*/
|
||||
public void setTo(String addstr, Object name) throws Exception {
|
||||
public void setTo(String addstr, Object name) {
|
||||
try {
|
||||
addRecipient(addstr, name, Message.RecipientType.TO);
|
||||
} catch (Exception mx) {
|
||||
System.err.println("Error in MailObject.setTo(): "+mx);
|
||||
setStatus(TO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -296,8 +323,14 @@ public class MailObject extends ScriptableObject implements Serializable {
|
|||
* @throws Exception ...
|
||||
* @throws AddressException ...
|
||||
*/
|
||||
public void addTo(String addstr, Object name) throws Exception {
|
||||
public void addTo(String addstr, Object name) {
|
||||
try {
|
||||
addRecipient(addstr, name, Message.RecipientType.TO);
|
||||
} catch (Exception mx) {
|
||||
System.err.println("Error in MailObject.addTO(): "+mx);
|
||||
setStatus(TO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -309,8 +342,13 @@ public class MailObject extends ScriptableObject implements Serializable {
|
|||
* @throws Exception ...
|
||||
* @throws AddressException ...
|
||||
*/
|
||||
public void addCC(String addstr, Object name) throws Exception {
|
||||
public void addCC(String addstr, Object name) {
|
||||
try {
|
||||
addRecipient(addstr, name, Message.RecipientType.CC);
|
||||
} catch (Exception mx) {
|
||||
System.err.println("Error in MailObject.addCC(): "+mx);
|
||||
setStatus(CC);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -322,8 +360,13 @@ public class MailObject extends ScriptableObject implements Serializable {
|
|||
* @throws Exception ...
|
||||
* @throws AddressException ...
|
||||
*/
|
||||
public void addBCC(String addstr, Object name) throws Exception {
|
||||
public void addBCC(String addstr, Object name) {
|
||||
try {
|
||||
addRecipient(addstr, name, Message.RecipientType.BCC);
|
||||
} catch (Exception mx) {
|
||||
System.err.println("Error in MailObject.addBCC(): "+mx);
|
||||
setStatus(BCC);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -358,10 +401,13 @@ public class MailObject extends ScriptableObject implements Serializable {
|
|||
|
||||
/**
|
||||
* Send the message.
|
||||
*
|
||||
* @throws Exception ...
|
||||
*/
|
||||
public void send() throws Exception {
|
||||
public void send() {
|
||||
// only send message if everything's ok
|
||||
if (status != OK) {
|
||||
System.err.println("Error sending mail. Status="+status);
|
||||
}
|
||||
try {
|
||||
if (buffer != null) {
|
||||
// if we also have a multipart body, add
|
||||
// plain string as first part to it.
|
||||
|
@ -381,5 +427,9 @@ public class MailObject extends ScriptableObject implements Serializable {
|
|||
}
|
||||
|
||||
Transport.send(message);
|
||||
} catch (Exception mx) {
|
||||
System.err.println("Error in MailObject.send(): "+mx);
|
||||
setStatus(SEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue