2011-05-18 75 views
2

我正在使用AbstractMailMessageSender從我們的應用程序向用戶發送電子郵件。 我已經擴展這個類以包含附件了。包含簽名的電子郵件

public void sendMessage() throws MessagingException { 
    MimeMessage msg = sender.createMimeMessage(); 
    MimeMessageHelper helper = new MimeMessageHelper(msg, true); 
    helper.setTo(this.to); 
    helper.setFrom(this.from); 
    helper.setSubject(this.subject); 
    helper.setText(this.message); 
    if (this.cc != null){ 
     helper.setCc(this.cc); 
    } 
    if (this.bcc != null){ 
     helper.setBcc(this.bcc); 
    } 
    for(String attachment : attachments.keySet()){ 
     helper.addAttachment(attachment, attachments.get(attachment)); 
    } 
    sender.send(msg); 
} 

我想在電子郵件中包含一個簽名。不幸的是,這個類沒有簽名方法。

我試圖將它與郵件正文一起發送,但我失去了換行符和格式。

任何幫助表示讚賞。 謝謝

+0

等待,什麼是MimeMessageHelper類?春天來了嗎?如果是這樣,請標記spring – Bozho 2011-05-18 17:47:40

+0

在整個interweb中唯一提及'AbstractMailMessageSender'就是* this *問題。 – skaffman 2011-05-18 17:53:14

+0

整個interweb和我的classpath :) – Bozho 2011-05-18 18:01:28

回答

2

我不認爲簽名是SMTP郵件的單獨部分。

您必須在文本中設置它,並確保您的格式不鬆散(這取決於消息的內容類型以及您設置的文本)。

從我看到你可能使用了錯誤的setText(..)方法。您可能必須使用setText(text, true)來指示使用了html。

當然,我認爲如果您使用的是html和格式,您將使用<br />作爲新行。事實證明,情況並非如此。

+0

你是對的,那是春天,你有解決方案 – 2011-05-18 17:55:35

+0

感謝您的迴應。是的,我正在使用setText(text,true)我所要做的只是將CR改爲
Viidhya 2011-05-18 18:05:40

+0

@Viidhya在你展示的內容中沒有使用它。請確保您顯示真實的代碼。 – Bozho 2011-05-18 18:06:26