For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Wednesday, May 07, 2014

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



      Incompatible type required: org.hibernate.Session found: javax.mail.Session 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 = "POP@mail.com";
        String tto = toEmail;
        String ssubject = "My subject" + new Date();
        String msgText = "My text message ";
        Properties properties = new Properties();
        properties.put("mail.smtp.host", "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.setSubject(ssubject);
            message.setSentDate(new Date());
            MimeBodyPart messagePart = new MimeBodyPart();
            messagePart.setText(msgText);
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(messagePart);
            message.setContent(multipart);
            Transport.send(message);
        } catch (MessagingException e) {
            System.out.println(e.toString());
        }
    }
 





Share:

0 comments:

Post a Comment

Add Dependent Scripts

   here is the code that allow to add dependent script :         <script>         const addDependentScripts = async function( scriptsT...

Ads Inside Post

Powered by Blogger.

Arsip