Skip to Content
0
Former Member
Mar 18, 2008 at 05:43 AM

Unable to send emails through adobe offline project.

19 Views

Hi Experts!!!

I am trying to send an email through Adobe Offline Form. I am quoting the code. Plz check what's the problem with the code.

// -


// This file has been generated partially by the Web Dynpro Code Generator.

// MODIFY CODE ONLY IN SECTIONS ENCLOSED BY @@begin AND @@end.

// ALL OTHER CHANGES WILL BE LOST IF THE FILE IS REGENERATED.

// -


package com.lifecyclelettersapplication;

//

// IMPORTANT NOTE:

// ALL IMPORT STATEMENTS MUST BE PLACED IN THE FOLLOWING SECTION ENCLOSED

// BY @@begin imports AND @@end. FURTHERMORE, THIS SECTION MUST ALWAYS CONTAIN

// AT LEAST ONE IMPORT STATEMENT (E.G. THAT FOR IPrivateFormView).

// OTHERWISE, USING THE ECLIPSE FUNCTION "Organize Imports" FOLLOWED BY

// A WEB DYNPRO CODE GENERATION (E.G. PROJECT BUILD) WILL RESULT IN THE LOSS

// OF IMPORT STATEMENTS.

//

//@@begin imports

import java.util.Properties;

import javax.mail.Address;

import javax.mail.BodyPart;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.SendFailedException;

import javax.mail.Session;

import javax.mail.Transport;

import javax.mail.internet.AddressException;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeBodyPart;

import javax.mail.internet.MimeMessage;

import javax.mail.internet.MimeMultipart;

import com.lifecyclelettersapplication.wdp.IPrivateFormView;

//@@end

//@@begin documentation

//@@end

public class FormView

{

/**

  • Logging location.

*/

private static final com.sap.tc.logging.Location logger =

com.sap.tc.logging.Location.getLocation(FormView.class);

static

{

//@@begin id

String id = "$Id$";

//@@end

com.sap.tc.logging.Location.getLocation("ID.com.sap.tc.webdynpro").infoT(id);

}

/**

  • Private access to the generated Web Dynpro counterpart

  • for this controller class. </p>

*

  • Use <code>wdThis</code> to gain typed access to the context,

  • to trigger navigation via outbound plugs, to get and enable/disable

  • actions, fire declared events, and access used controllers and/or

  • component usages.

*

  • @see com.lifecyclelettersapplication.wdp.IPrivateFormView for more details

*/

private final IPrivateFormView wdThis;

/**

  • Root node of this controller's context. </p>

*

  • Provides typed access not only to the elements of the root node

  • but also to all nodes in the context (methods node<i>XYZ</i>())

  • and their currently selected element (methods current<i>XYZ</i>Element()).

  • It also facilitates the creation of new elements for all nodes

  • (methods create<i>XYZ</i>Element()). </p>

*

  • @see com.lifecyclelettersapplication.wdp.IPrivateFormView.IContextNode for more details.

*/

private final IPrivateFormView.IContextNode wdContext;

/**

  • A shortcut for <code>wdThis.wdGetAPI()</code>. </p>

  • Represents the generic API of the generic Web Dynpro counterpart

  • for this controller. </p>

*/

private final com.sap.tc.webdynpro.progmodel.api.IWDViewController wdControllerAPI;

/**

  • A shortcut for <code>wdThis.wdGetAPI().getComponent()</code>. </p>

  • Represents the generic API of the Web Dynpro component this controller

  • belongs to. Can be used to access the message manager, the window manager,

  • to add/remove event handlers and so on. </p>

*/

private final com.sap.tc.webdynpro.progmodel.api.IWDComponent wdComponentAPI;

public FormView(IPrivateFormView wdThis)

{

this.wdThis = wdThis;

this.wdContext = wdThis.wdGetContext();

this.wdControllerAPI = wdThis.wdGetAPI();

this.wdComponentAPI = wdThis.wdGetAPI().getComponent();

}

//@@begin javadoc:wdDoInit()

/** Hook method called to initialize controller. */

//@@end

public void wdDoInit()

{

//@@begin wdDoInit()

/* The following lines initialize the context elements;

  • Enter your e-mail id in the set From-method

*/

//wdContext.currentContextElement().setTeststatus(" do in it");

try{

wdContext.currentEmailElement().setFrom("umang.mathur@zmail.ril.com");

wdContext.currentEmailElement().setTo("umang.mathur@zmail.ril.com");

wdContext.currentEmailElement().setCc("abhayadeep.singh@ril.com");

wdContext.currentEmailElement().setBcc("sanjyoti.lengare@ril.com");

// wdContext.currentEmailElement().setCc(" ");

// wdContext.currentEmailElement().setBcc(" ");

wdContext.currentEmailElement().setSubject("Test Mail By Umang");

wdContext.currentEmailElement().setBody("You will find the address proof letter in the attachment of this e mail. Please sign this form and send it.");

}

catch(Exception e)

{

wdContext.currentContextElement().setTeststatus("do in it"+e.getMessage());

}

//@@end

}

//@@begin javadoc:wdDoExit()

/** Hook method called to clean up controller. */

//@@end

public void wdDoExit()

{

//@@begin wdDoExit()

//@@end

}

//@@begin javadoc:wdDoModifyView

/**

  • Hook method called to modify a view just before rendering.

  • This method conceptually belongs to the view itself, not to the

  • controller (cf. MVC pattern).

  • It is made static to discourage a way of programming that

  • routinely stores references to UI elements in instance fields

  • for access by the view controller's event handlers, and so on.

  • The Web Dynpro programming model recommends that UI elements can

  • only be accessed by code executed within the call to this hook method.

*

  • @param wdThis Generated private interface of the view's controller, as

  • provided by Web Dynpro. Provides access to the view controller's

  • outgoing controller usages, etc.

  • @param wdContext Generated interface of the view's context, as provided

  • by Web Dynpro. Provides access to the view's data.

  • @param view The view's generic API, as provided by Web Dynpro.

  • Provides access to UI elements.

  • @param firstTime Indicates whether the hook is called for the first time

  • during the lifetime of the view.

*/

//@@end

public static void wdDoModifyView(IPrivateFormView wdThis, IPrivateFormView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

{

//@@begin wdDoModifyView

//@@end

}

//@@begin javadoc:onPlugFromFirstview(ServerEvent)

/** Declared validating event handler. */

//@@end

public void onPlugFromFirstview(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onPlugFromFirstview(ServerEvent)

wdContext.currentContextElement().setTeststatus("from first view");

//wdDoInit();

//@@end

}

//@@begin javadoc:onActionBack(ServerEvent)

/** Declared validating event handler. */

//@@end

public void onActionBack(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionBack(ServerEvent)

wdThis.wdFirePlugToFirstView();

//@@end

}

//@@begin javadoc:onActionSend(ServerEvent)

/** Declared validating event handler. */

//@@end

public void onActionSend(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionSend(ServerEvent)

Properties props = new Properties();

String host = "rmail070.zmail.ril.com";

props.put("rmail070.zmail.ril.com", host);

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

MimeMessage message = new MimeMessage(session);

Address toAddress = new InternetAddress();

Address fromAddress = new InternetAddress();

Address ccAddress = new InternetAddress();

Address bccAddress = new InternetAddress();

wdContext.currentContextElement().setTeststatus("1");

try

{

MimeMultipart multipart = new MimeMultipart();

wdContext.currentContextElement().setTeststatus("2");

BodyPart messageBodyPart = new MimeBodyPart();

if (! wdContext.currentEmailElement().getFrom().equals(""))

{

fromAddress = new InternetAddress(wdContext.currentEmailElement().getFrom());

message.setFrom(fromAddress);

}

wdContext.currentContextElement().setTeststatus("3");

if (! wdContext.currentEmailElement().getTo().equals(""))

{

toAddress = new InternetAddress(wdContext.currentEmailElement().getTo());

message.setRecipient(Message.RecipientType.TO, toAddress);

}

wdContext.currentContextElement().setTeststatus("4");

if (! wdContext.currentEmailElement().getCc().equals(""))

{

ccAddress = new InternetAddress(wdContext.currentEmailElement().getCc());

message.setRecipient(Message.RecipientType.CC, ccAddress);

}

wdContext.currentContextElement().setTeststatus("5");

if (! wdContext.currentEmailElement().getBcc().equals(""))

{

bccAddress = new InternetAddress(wdContext.currentEmailElement().getBcc());

message.setRecipient(Message.RecipientType.BCC, bccAddress);

}

wdContext.currentContextElement().setTeststatus("6");

if (! wdContext.currentEmailElement().getSubject().equals(""))

{

message.setSubject(wdContext.currentEmailElement().getSubject());

}

wdContext.currentContextElement().setTeststatus("7");

if (! wdContext.currentEmailElement().getBody().equals(""))

{

messageBodyPart.setText(wdContext.currentEmailElement().getBody());

}

wdContext.currentContextElement().setTeststatus("8");

multipart.addBodyPart(messageBodyPart);

wdContext.currentContextElement().setTeststatus("10");

//// A new part will be added this will be the attachment

messageBodyPart = new MimeBodyPart();

// String filename = "temp
webdynpro
web
local
LifeCycleLetters
Components
com.lifecyclelettersapplication.LifeCycleLettersApplication
LifeCycle.pdf";

// DataSource source = new FileDataSource(filename);

// messageBodyPart.setDataHandler(new DataHandler(source));

// messageBodyPart.setFileName(source.getName());

// messageBodyPart.setHeader("Content-Type","application/pdf");

// multipart.addBodyPart(messageBodyPart);

message.setContent(multipart);

Transport.send(message);

wdContext.currentContextElement().setTeststatus("11");

}

catch (AddressException e)

{

wdComponentAPI.getMessageManager().reportWarning(e.getLocalizedMessage());

e.printStackTrace();

}

catch (SendFailedException e)

{

wdComponentAPI.getMessageManager().reportWarning(e.getLocalizedMessage());

e.printStackTrace();

}

catch (MessagingException e)

{

wdComponentAPI.getMessageManager().reportWarning(e.getLocalizedMessage());

e.printStackTrace();

}

catch(Exception e)

{

wdContext.currentContextElement().setTeststatus("action send"+e.getMessage());

}

//

//@@end

}

/*

  • The following code section can be used for any Java code that is

  • not to be visible to other controllers/views or that contains constructs

  • currently not supported directly by Web Dynpro (such as inner classes or

  • member variables etc.). </p>

*

  • Note: The content of this section is in no way managed/controlled

  • by the Web Dynpro Designtime or the Web Dynpro Runtime.

*/

//@@begin others

//@@end

}