Skip Ribbon Commands
Skip to main content

Documentum Resources

:

Code Samples: Send email through method

Documentum Resources

import java.util.*;
import java.math.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.print.DocFlavor.STRING;

import java.io.OutputStream;

import com.documentum.mthdservlet.IDmMethod;
import com.documentum.fc.client.*;
import com.documentum.fc.common.*;
import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;

public class firstMethod implements IDmMethod
{
public void execute(Map params, OutputStream ostream) throws Exception
{
try
{
DfLogger.error(this,"Sending Mail In Execute",null,null);
this.sendEmail(null,null,null,null);
DfLogger.error(this,"Mail Sent In Execute",null,null);
}
finally
{
DfLogger.error(this,"In Execute-Finally In Execute",null,null);
}
}

private void sendEmail(String sender, String recipient, String subject1, String body1)
{
String mailHost = "smtpServer";
String to =receiver@gmail;
String from =sender@gmail;
String subject = "JavaTest1";
String body = "Testing 1 2 3";

if ((from != null) && (to != null) && (subject != null) && (body != null)) // we have mail to send
{
try
{
DfLogger.error(this,"Preparing Properties In SendEmail",null,null);
//Get system properties
Properties props = System.getProperties();

//Specify the desired SMTP server
props.put("mail.smtp.host", mailHost);

DfLogger.error(this,"Preparing Session In SendEmail",null,null);
// create a new Session object
Session session = Session.getInstance(props,null);

DfLogger.error(this,"Preparing Message In SendEmail",null,null);
// create a new MimeMessage object (using the Session created above)
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, new InternetAddress[] { new

InternetAddress(to) });
message.setSubject(subject);
message.setContent(body, "text/plain");

DfLogger.error(this,"Sending Message In SendEmail",null,null);
//Transport.send(message);
DfLogger.error(this,"Message Sent In SendEmail",null,null);

}
catch (Throwable t)
{
DfLogger.error(this,"In Catch In SendEmail",null,t);
}
finally
{
DfLogger.error(this,"In Finally In SendEmail",null,null);
}
}
}
}