cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Email Notifications

Former Member
0 Kudos

I have read several threads on this topic but no results. I have developed a web dypro application which attempts to send a request to our smtp server (see code at end). However, the application continues to fail with cannot send request to smtp server. My network team confirmed the smtp server can receive relays from the j2ee server,etc.

On a second note, I have seen references to people using

the "com.sap.security.core.util.notification.SendMailAsynch" class. However, I find no references in the J2EE APIs.

This project seems straight forward but I cannot get over this hurdle. Any assistance will be rewarded.

I added the smtp jar to my project and have many variations of the following code:

String msgText = "This is a message body.\nHere's the second line.";

String to = "stephen.king@aei.com";

String from = "stephen.king@aei.com";

String host = "outhostserver";

boolean debug = true;

// create some properties and get the default Session

Properties props = new Properties();

props.put("mail.smtp.host", host);

if (debug) props.put("mail.debug", "true");

Session session = Session.getInstance(props, null);

session.setDebug(debug);

try {

// create a message

Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));

InternetAddress[] address = {new InternetAddress("stephen.king@aei.com")};

msg.setRecipients(Message.RecipientType.TO, address);

msg.setSubject("JavaMail APIs Test");

msg.setSentDate(new java.sql.Date(System.currentTimeMillis()));

// If the desired charset is known, you can use

// setText(text, charset)

msg.setText(msgText);

Transport.send(msg);

} catch (MessagingException mex) {

wdContext.currentContextElement().setTexterror(mex.getMessage());

System.out.print("####TODAY =" + new java.sql.Date(System.currentTimeMillis()).toString());

System.out.print(mex.getStackTrace());

}

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Stephen:

I suggest you that configures the smtp service inside the Visual Administrator and then you can send mails by the next way:

try {

ChannelFactory channelFactory = ChannelFactory.getInstance();

String from = "me@mydomain.com"

String to = "you@yourdomain.com;

String subject = "Hello;

String body = "Come to my party next saturday, you know my address, bring a TEQUILA";

IChannel channel = channelFactory.getChannel(ChannelFactory.EMAIL);

channel.sendTo(to,from,subject,body,"text/html");

} catch (Exception e) {

e.printStackTrace();

}

Good luck!!!

Josue Cruz

Former Member
0 Kudos

How can I configure Visual Administrator for this purpose.If you knows,please tell me it stepwise.