cancel
Showing results for 
Search instead for 
Did you mean: 

Send email with attachment

Former Member
0 Kudos

Hi,

I like to send a e-mail with or without attachment.

I succesfully implemented the ISendMailService, but after a little research it seems to me that it is not possible to add an attachment.

After searching on SDN I found information about Collaboration > Groupware > Mail. I also found this document 'How to build a Groupware Connector'!

The question is: Is it possible to realize my wanted functionality with the mail part in collaboration\groupware?

When Yes, then it seems to me that i need to implement a transport with the following implements: IMailSendTransport, ISendTransport

The transport class now needs to implement a method initialize with the following inputparameters IGWResourceManager and a List.

My questions are:

How do I get a the IGWResourceManager initialized?

What does the List parameter (called configuration) expects?

Answers of example code or any other information to get a mail function working is very welcome!

Kind regards.

Marinus

Accepted Solutions (1)

Accepted Solutions (1)

detlev_beutner
Active Contributor
0 Kudos

Hi Marinus,

at a first glance, you should be able to use the two following APIs already implemented within KMC (you only need the corresponding settings done):

a) Create an IMailItem and send it via IMailSendTransport; the IMailItem has got the method <i>addAttachment</i>

b) Create an ISendMailItem and send it via ISendMailService; the ISendMailItem has got the method <i>setAttachmentList</i>

For details check out the portal applications and their implementation classes com.sap.netweaver.coll.appl.gw and/or com.sap.netweaver.coll.shared (just decompile the parts which sound interesting).

> I succesfully implemented the ISendMailService

You don't have to implement that service, it is already implemented (com.sap.ip.collaboration.gw.impl.service.mail.SendMailService).

Hope it helps

Detlev

PS: Please consider rewarding points for helpful answers on SDN. Thanks in advance!

Former Member
0 Kudos

Hi Detlev,

Thanks for your comment.

- I check out option b, but the ISendMailItem does not have a method setAttachmentList! I am on SP12, is that the reason?

- So I guess I have to go for option A. The question there is that the initialize expect the following parameters <i>(IGWResourceManager gwManager, List configuration)</i>.

My question here is how do i get a instance of the type IGWResourceManager.

Something like this:

IGWResourceManager gwManager = <b><i>???[what to implement here]???;</i></b>

IGroupwareItemFactory gwFactory =

gwManager.getGroupwareItemFactory(ep5User);

When I have this code I can create a IAttachment, IMailItem and I can initialize the transport!

Really hope you can help!

Marinus

detlev_beutner
Active Contributor
0 Kudos

Hi Marinus,

now I've checked these things more in details and it really seems that option A is not accessible from outside.

My checks have been against an KMC SP15 installation, so the differences may be due to the version difference.

Anyhow, you still can use standard JavaMail; you can even use at least the settings for a mail server from the configuration, so that you don't have to add an extra configuration for this.

Hope it helps

Detlev

Former Member
0 Kudos

Hi Detlev,

I very thankful for you more detailed look. Now I am sure that I don't have to spend more time at option A.

You say that I can use standard JavaMail do you mean with this option B or do you mean the MailSession option. Which is explained in the Blog 'Develop a Web Service that sends an Email'.

If you mean option B does it have a setAttachmentList method in SP15?

If you mean option 'MailSession' does this have a add attachment method?

Anyway I am very pleased if your help. I will award you points.

Kind regards.

Marinus

detlev_beutner
Active Contributor
0 Kudos

Hi Marinus,

> use standard JavaMail do you mean with this option B

> or do you mean the MailSession option

When I wrote this I meant "pure JavaMail", not option B.

Anyhow, option B has setAttachmentList in SP15, as already stated, so if you could upgrade to a SP level where this is provided, this is maybe the more elegant method to reuse the given KM java service implementation.

Hope it helps

Detlev

Former Member
0 Kudos

Hi,

One (last) question. I like to use the setToList method.

I got a ClassCastException, but that was due to using the wrong object. So what i thougth was that I need to use the IEmailAddress interface. So I made a own implemention of this interface.

But that is the problem I have no idea how to implement this class. This is mine implementation so far:

<i>public class EmailAddress implements IEmailAddress {

String _name;

String _address;

public IEmailAddress setName(String name) {

_name = name;

return this;

}

public String getName() {

return _name;

}

IEmailAddress setAddress(String address) throws MalformedURLException {

_address = address;

return this;

}

public String getAddress() {

return _address;

}</i>

I do not get the ClassCastException anymore, but the mail address which are used now are totally mess up!

I don't know if mine knowledge of Java is leaking of that the use of this API is quit difficult. Anyway I hope you can give some help of a hint.

Marinus

detlev_beutner
Active Contributor
0 Kudos

Hi Marinus,

even if you implement IEmailAddress, it must have a toString method, which is used in class <i>AbstractGroupwareItem</i>, method <i>toEmailAddressString</i>.

Anyway, you can use

GWUtils.getEmailAddress(...)

from com.sap.netweaver.coll.appl.ui.gw

Hope it helps

Detlev

Former Member
0 Kudos

Hi Detlev,

I added a toString method and it works.

So i am very thankful for that.

Anyway i checked out the ISendMailItem interface and I saw a setAttachmentList(IAttachmentList iAttachmentList) method.

So I guess that I have to make a own implementation of the ISendMailItem, IAttachmentList and IAttachment.

I hope I will succeed with this.

But for the moment I am satisfied. I am very pleased with all your help.

Kind regards. Marinus

Former Member
0 Kudos

Hi Detlev,

I extended by my mail application further. It looks better and better! But I just discovered something!

If I give the following String to the mail service (I use the setContent method):

========(This is how it is shown in WD)=============

Hi Detlev,

This is a test mail!

Greetz, Marinus

==================================

But when I see the mail in my mail client (MS Outlook) then I see the mail formatted like this.

==================================

Hi Detlev, This is a test mail! Greetz, Marinus

==================================

So I lost my layout!

This is really a show stopper. I though that a statement like this would help setMimeType("text/plain"). But that isn't the case.

Have you any idea?

Kind regards, Marinus

Former Member
0 Kudos

Hi Detlev,

I am also busy with the attachments. I trying to make a own implementation of the IAttachmentList!

This is my code:

<i>public class AttachmentList implements IAttachmentList {

IResourceList list;

public AttachmentList() {

super();

list = new ResourceList();

}

public IResourceList getAttachments() throws AttachmentException {

return list;

}

public void deleteAttachment(IResource resource) throws AttachmentException {

list.remove(resource);

}

public void addAttachment(IResource resource) throws AttachmentException {

list.add(resource);

}

public int getAttachmentCount() throws AttachmentException {

return list.size();

}

}</i>

When I know add a resource to the list and add the list to the mailitem I get the following error:

<i>java.lang.NullPointerException at com.sap.ip.collaboration.gw.impl.service.mail.SendMailItemImpl.addAttachmentList(SendMailItemImpl.java:261)</i>

So the implementation is not correct or I need to implement more methods.

But were to start! There is no documentation!!!

Hope you have time to help!

Marinus

detlev_beutner
Active Contributor
0 Kudos

Hi Marinus,

just check the source of the class where the exception is raised:

/* 259*/                        AttachmentType type = attachmentList.getAttachmentType(res);
/* 261*/                        if (type.equals(AttachmentType.LINK)) {

So getAttachmentType(res) is needed to return something...

Just to give you more info where you could look into to get some idea how the attachements are managed within the standard: Decompile UIUtils, AttachmentListManager, GlobalAttachmentManager.

Hope it helps

Detlev

detlev_beutner
Active Contributor
0 Kudos

Hi Marinus,

> So I lost my layout!

You should check the details of the message as it arrives at Outlook. Double-Click on the message, View - Options - Internet Header Lines (I've just tried to translate from german: Ansicht - Optionen - Internetkopfzeilen). Check content-type etc.

Hope it helps

Detlev

Former Member
0 Kudos

Hi Detlev,

Thanks again.

I return now an AttachmentType in the method getAttachmentType and I get an attachment by the mail.

I am very happy with that!

As you say with decompiling classes you can find much more information. So I tried to decompile files with a tool named ‘mocha’. But it failed to decompile the AttachmentListManager, GlobalAttachmentManager, SendMailItemImpl. Some other classes are decompiled proper!

So my question is which tool do you use?

About the layout problem:

The mail had the contentType = <i>text/html; charset=UTF-8</i>

Since I attach a attachment the contentType = <i>multipart/mixed; boundary="----=_Part_12_8472069.1137596177142"</i>

So I hope you have any suggestions! As I said it is a kind of show stopper for us!

Anyway. I very grateful with your help!

Marinus

detlev_beutner
Active Contributor
0 Kudos

Hi Marinus,

> Thanks again.

You're welcome. Feel free to reward additional points

> which tool do you use?

"The one and only", JAD, or to be more precise, DJ, which is based on JAD. DJ has become commercial in the meantime, but you can download the last free version here: ftp://ftp.sac.sk/pub/sac/utilprog/djdec377.zip

> any suggestions

The most simple suggestion of course is that you make use of the content-type, i.e. use <br> for a line break!

Otherwise you would have to care about the possibility to set the content-type for the message to pure text, but I'm unsure if the API provides that possibility - you have to have in mind that this is primarily an API for internal portal usage, and if the developers have decided to mail HTML always (which - on the other hand - I don't hope for HTML mails are somewhat PFUI) - your unluck.

Hope it helps

Detlev

Former Member
0 Kudos

Hi Detlev,

Your solution with <br> was the solution. I should though of that myself.

I downloaded JAD and will have a look at it and use it.

So my e-mail client is finally finished. I am thinking to make a Blog about it, if I have time.

So thankx for all your help. I rewarded points.

Kind regards,

Marinus

Answers (1)

Answers (1)

Former Member
0 Kudos

Dear Sir,

We are trying to build a portal application using AbstractGroupwareItem. But we are not able to understand how to go about it. From the forum we found out that you have already implemented the mailing service. Can you please guide us how to go about it.

Hoping to receive a reply.

Thanks a lot.

Regards,

Ranu