Monday, 17 November 2014

Incompatible type required: org.hibernate.Session found

Incompatible type required: org.hibernate.Session found: javax.mail.Session Java mail struts and hibernate at the same time

How to use Java mail struts and hibernate at the same time?


When you work with hibernate in java and want to use java email then you will face
the error, incompatible type required: org.hibernate.Session found: javax.mail.Session
This is because Session is in both package, so you needed to explicit declaration.
Use the listed below email code in java hibernate and you will not face the above error.

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import org.hibernate.Query;
public void sendEmailToAll(String toEmail){
        String ffrom = "";
        String tto = toEmail;
        String ssubject = "My subject" + new Date();
        String msgText = "My text message ";
        Properties properties = new Properties();
        properties.put("", "my email ip");
        javax.mail.Session ss = javax.mail.Session.getDefaultInstance(properties,null);
        try {
            MimeMessage message = new MimeMessage(ss);
            message.setFrom(new InternetAddress(ffrom));
            message.setRecipient(Message.RecipientType.TO, new InternetAddress(tto));
            message.setSentDate(new Date());
            MimeBodyPart messagePart = new MimeBodyPart();
            Multipart multipart = new MimeMultipart();
        } catch (MessagingException e) {

No comments:

Post a Comment