jadex.bdi.planlib.messaging.SendEmailPlan Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-applib-bdi Show documentation
Show all versions of jadex-applications-applib-bdi Show documentation
The Jadex applib BDI package contains ready to use functionalities for BDI agents mostly in form of modules called capabilities.
The newest version!
package jadex.bdi.planlib.messaging;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import jadex.bdiv3x.runtime.Plan;
/**
* Send an email.
*/
public class SendEmailPlan extends Plan
{
/**
* The body method is called on the
* instatiated plan instance from the scheduler.
*/
public void body()
{
// Account settings.
EmailAccount account = (EmailAccount)getParameter("account").getValue();
if(account==null)
fail();
// Message settings.
String content = (String)getParameter("content").getValue();
String subject = (String)getParameter("subject").getValue();
String[] receivers = (String[])getParameterSet("receivers").getValues();
String[] ccs = (String[])getParameterSet("ccs").getValues();
String[] bccs = (String[])getParameterSet("bccs").getValues();
// Todo: attachments?
// Object[] attachments = getParameterSet("attachments").getValues(); // todo:
Properties props = new Properties();
props.setProperty("mail.smtp.auth","true");
props.setProperty("mail.smtps.auth","true");
Session sess= Session.getDefaultInstance(props, null);
sess.setDebug(true);
try
{
MimeMessage message = new MimeMessage(sess);
message.setFrom(new InternetAddress(account.getSender()));
message.setContent(content, "text/ plain");
message.setSubject(subject);
for(int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy