Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

send mail using java in oracle 11g

madhu GNov 8 2014 — edited Nov 13 2014

I using 11g database..

I have created a procedure to send mail using java..as below

[code]

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "SendAttach" AS

import java.util.Properties;

import javax.mail.*;

import javax.mail.internet.*;

import javax.activation.*;

public class SendAttach {

public static void sendmail(String recipient,String subject,String msg,String file)

{

String host="smtp.gmail.com";

final String user="memadhuh@gmail.com";//change accordingly

final String password="psd";//change accordingly

String to=recipient;//change accordingly

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 session = Session.getDefaultInstance(props,

 new javax.mail.Authenticator() {

   protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(user,password);

   }

 });

 try {

  MimeMessage message = new MimeMessage(session);

  message.setFrom(new InternetAddress(user));

  message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));

  message.setSubject(subject);

  BodyPart messageBodyPart1 = new MimeBodyPart();  //newly added

  messageBodyPart1.setText(msg);  //newly added

  message.setText(msg);

  MimeBodyPart messageBodyPart = new MimeBodyPart();

  Multipart multipart = new MimeMultipart();

  messageBodyPart = new MimeBodyPart();

  String file1 = file;

  String fileName = "sql";

  DataSource source = new FileDataSource(file1);

  messageBodyPart.setDataHandler(new DataHandler(source));

  messageBodyPart.setFileName(fileName);

  multipart.addBodyPart(messageBodyPart);

  multipart.addBodyPart(messageBodyPart1);

message.setContent(multipart);

 Transport.send(message);

  System.out.println("message sent successfully...");

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

}

}

/

It works finw with sysdba login.

But it gives below error when i connected as user(ori) my user name

prs.png

Help me to resolve the problem...

This post has been answered by madhu G on Nov 13 2014
Jump to Answer

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 11 2014
Added on Nov 8 2014
9 comments
7,148 views