Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化Exception #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/main/java/io/github/biezhi/ome/OhMyEmail.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
public class OhMyEmail {

private static Session session;
private static String user;
private static String user;

private MimeMessage msg;
private String text;
private String html;
private MimeMessage msg;
private String text;
private String html;
private List<MimeBodyPart> attachments = new ArrayList<MimeBodyPart>();

private OhMyEmail() {
Expand Down Expand Up @@ -200,8 +200,12 @@ public OhMyEmail bcc(String... bcc) throws SendMailException {
}
}

public OhMyEmail bcc(String bcc) throws MessagingException {
return addRecipient(bcc, Message.RecipientType.BCC);
public OhMyEmail bcc(String bcc) throws SendMailException {
try {
return addRecipient(bcc, Message.RecipientType.BCC);
} catch (MessagingException e) {
throw new SendMailException(e);
}
}

private OhMyEmail addRecipients(String[] recipients, Message.RecipientType type) throws MessagingException {
Expand Down Expand Up @@ -241,8 +245,8 @@ public OhMyEmail attachURL(URL url, String fileName) throws SendMailException {
}

private MimeBodyPart createAttachment(File file, String fileName) throws SendMailException {
MimeBodyPart attachmentPart = new MimeBodyPart();
FileDataSource fds = new FileDataSource(file);
MimeBodyPart attachmentPart = new MimeBodyPart();
FileDataSource fds = new FileDataSource(file);
try {
attachmentPart.setDataHandler(new DataHandler(fds));
attachmentPart.setFileName(null == fileName ? MimeUtility.encodeText(fds.getName()) : MimeUtility.encodeText(fileName));
Expand Down Expand Up @@ -271,8 +275,8 @@ public void send() throws SendMailException {
}

MimeMultipart cover;
boolean usingAlternative = false;
boolean hasAttachments = attachments.size() > 0;
boolean usingAlternative = false;
boolean hasAttachments = attachments.size() > 0;

try {
if (text != null && html == null) {
Expand Down