0

JSP を使用してメールを送信しようとしています。html ファイルを送信でき、画像もメールに表示されますが、画像の配置が適切ではありません。(つまり、理想的な場所から再配置された画像)。CSSを編集しようとしていますが、うまくいきません。

ありがとう 。

package mail;

 public class Emailer {

private static final String staticAbove = "<html><head>"
        + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">"
        + "<title>Insert title here</title>"
        + "</head><body>"
        + "<div class=\"background\" style=\"background-color: #d6d6d6; width: 510px; height: 980px; margin-left: 725px;\">"
        + "<font color=\"#868384\" size=\"2\" style=\"margin-left: 100px;\"><br>"
        + "If you are unable to see images <u><a href = \"emailer.html\">click here for HTML version</a></u>"
        + "</font>"
        + "<div class=\"foreground\" style=\"z-index: 5;\">"
        + "<div style=\"position: relative; left: 0; top: 0;\">"
        +           + "</div></div>"
        + "<div class=\"whiteAboveGray\" style=\"background-color: white; margin-right: 15px; margin-left: 15px; margin-bottom: 15px; height: 650px; margin-top: -54px;\">"
        + "<div class=\"content\">"
        + "<h1> <font color=\"388293\" size=\"4\" face=\"TImes New Roman\" style=\"margin-top: 8px; margin-right: 8px; margin-bottom: 8px; margin-left: 8px;\">Dear Customer ,</font>"
        + "</h1>"
        + "<hr class=\"hr\" style=\"background-color: silver;\">"
        + "<font color=\"928888\">"
        + "<p align=\"justify\" style=\"margin-top: 8px; margin-right: 8px; margin-bottom: 8px; margin-left: 8px;\">"
                    + "</p>"
        + "<p align=\"justify\" style=\"margin-top: 8px; margin-right: 8px; margin-bottom: 8px; margin-left: 8px;\">"


        + "<p align=\"justify\" style=\"margin-top: 8px; margin-right: 8px; margin-bottom: 8px; margin-left: 8px;\">"
        + "</font>";
;

private static final String dynamicContent = "<div class=\"dyanamicContent\">"

        + 

上記はhtmlコードです。弦は3本。ここでこれらの文字列を使用しています..

  package mail;

  import java.util.List;
  import java.util.Properties;

   import javax.mail.Message;
   import javax.mail.MessagingException;
   import javax.mail.PasswordAuthentication;
   import javax.mail.Session;
   import javax.mail.Transport;
   import javax.mail.internet.InternetAddress;
   import javax.mail.internet.MimeMessage;

   import com.sun.mail.handlers.message_rfc822;

パブリック クラス MailUtility {

private static final String STATUS_ARCHIVE = "archive";

private CoverLetter coverLetter;
List<MailPropertiesInfo> successfullPropertiesList;

private static final String EMAIL_ID = "";
private static final String PASSWORD = "";

public void sendSuccessMail(List<MailPropertiesInfo> successfullPropertiesList, String sendToEmailId, String propertyId)
{
    Message message = initializeMailSetting(sendToEmailId);
    coverLetter = new CoverLetter();
    String messageForUSerHavingProperties = CoverLetter.getMessageforuserhavingproperties();
    StringBuilder content = getContent(successfullPropertiesList);

    try 
    {
        message.setSubject("");
        message.setContent(messageForUSerHavingProperties
                +"<b><u>Your Property ID is:  </b>"
                + propertyId+"</u>\n\n"+content,
                "text/html");

        Transport.send(message);
    //out.println("<b>Done</b>");
    } 
    catch(MessagingException me) {
        me.printStackTrace();
    }
}

private StringBuilder getContent(
        List<MailPropertiesInfo> successfullPropertiesList) {

    StringBuilder content = new StringBuilder();
    int count = 0;

    for(MailPropertiesInfo mailProp : successfullPropertiesList)
    {
        content.append(mailProp.toString());
        content.append("\n\n");
        count++;
        if(count == 5) 
        {
            break;
        }
    }   

    return content;
}

public void sendNoPropertiesMail(String sendToEmailId, String propertyId) 
{

    Message message = initializeMailSetting(sendToEmailId);

    coverLetter = new CoverLetter();
    String messageForUserNotHavingProperties = CoverLetter.getMessageforusernothavingproperties();
    try 
    {
        message.setSubject("Property Suggestion From DoMyDeal");
        message.setContent(Emailer.getStaticabove()+Emailer.getDynamiccontent()+Emailer.getStaticbelow() 
                +"<b><u>Your Property ID is: </b>"
                +propertyId,
                "text/html");
        Transport.send(message);
    } 
    catch(MessagingException me) {
        me.printStackTrace();
    }
}

private Message initializeMailSetting(String sendToEmailId) {
    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "465");

    Session session123 = Session.getInstance(props,
        new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(EMAIL_ID,PASSWORD);
            }
        });

    Message message = null ;

    try
    {
        message = new MimeMessage(session123);
        message.setFrom(new InternetAddress("domydealportal@gmail.com"));
        message.setRecipients(Message.RecipientType.TO,
        InternetAddress.parse(sendToEmailId));              

    }
    catch (MessagingException e)
    {
            e.printStackTrace();
    }

    return message;
}

public CoverLetter getCoverLetter() {
    return coverLetter;
}

public void setCoverLetter(CoverLetter coverLetter) {
    this.coverLetter = coverLetter;
}

public List<MailPropertiesInfo> getSuccessfullPropertiesList() {
    return successfullPropertiesList;
}

public void setSuccessfullPropertiesList(
        List<MailPropertiesInfo> successfullPropertiesList) {
    this.successfullPropertiesList = successfullPropertiesList;
}

}

4

1 に答える 1

0

したがって、私のヒントは、divs を使用せず、メールのデザインにのみテーブルを使用することです。または、http://mailchimp.com/resources/html-email-templates/ のようなテスト済みの電子メール テンプレートを使用します

于 2013-02-04T08:38:03.143 に答える