Sending MMS using Java and Now-SMS and Creating MMS files using Jav...

Sending MMS using Java and Now-SMS and Creating MMS files using Jav... SearchSearch

SMS & MMS Technical Forum » NowSMS Support - MMS & Advanced Issues (Product Support Only) » Archive through July 14, 2004 » Sending MMS using Java and Now-SMS and Creating MMS files using Java and C# « Previous || Next »
Author Message
Yoram Givon
New member
Username: Yoram_gi

Post Number: 11
Registered: 11-2003
Posted on Sunday, April 25, 2004 - 05:56 pm:   

Hi all,
I have received lately some Emails from people regarding a post I wrote with an Example jave code on how to send MMS files with Now SMS.
I have lately alos ported Nokia MMS API to C#.

In the spirit of open source code I will be gald to share this information.
So if you need any help with these two issues just drop me an Email and I will send you sample code.

BR
Yoram
Rehman Adil
Unregistered guest
Posted on Friday, April 30, 2004 - 08:28 am:   

Hi,

Could you give me a reference to some documentation/sample code about handling Mime Content in C#. I have the required functionality present in Java but I need to transform the code to C#. Below I attach the code that I have.
There are a couple of classes in Dot Net Framework but I am unable to find a good example and short of time. Thanks in Advance.

Regards,
Rehman Adil

/**
* This class holds the content of an MMS message, it is responsible for
* composing the message and has the ability to return the content as a byte[]
*/
public class MMSMessageContent extends MimeMultipart
{
public MMSMessageContent()
{}

/**
* Adds a part (String) to the message content.
* It is expected to be us-ascii text.
* @param aTextPart The String to be added.
*/
public void addTextMedia(String aTextPart)
{
try
{
MimeBodyPart mbp = new MimeBodyPart();
mbp.setText(aTextPart, "us-ascii");
mbp.addHeader("Content-Type", mbp.getContentType());
addBodyPart(mbp);
}
catch (MessagingException e)
{
throw new RuntimeException(e.getMessage());
}
}

/**
* Adds a part (mediaobject) to the message content.
* @param aFilename A filename refering to a file of which a
* MimeBodyPart is created and added to the MMSContent
*/
public void addMedia(String aFilename)
{
try
{
FileDataSource fds = new FileDataSource(aFilename);
MimetypesFileTypeMap map = new MimetypesFileTypeMap();

MimeBodyPart mbp = new MimeBodyPart();
mbp.setDataHandler(new DataHandler(fds));
mbp.setHeader("Content-Type",
map.getContentType(aFilename));
mbp.setHeader("Content-Transfer-Encoding", "base64");
// mbp.setContentID("CONT" + getCount());
addBodyPart(mbp);
}
catch (MessagingException e)
{
throw new RuntimeException(e.getMessage());
}
}

/**
* Adds a Byte Array bodypart
* @param aByteBodyPart the Byte bodypart that has to be added
* @param aContentType the content type of the bodypart
*/
public void addByteArrayBodyPart(byte[] aByteBodyPart, String aContentType)
{
try
{
ByteArrayInputStream bis = new ByteArrayInputStream(aByteBodyPart);
MimeBodyPart mbp = new MimeBodyPart(bis);

mbp.setHeader("Content-Type", aContentType);
// mbp.setContentID("CONT" + getCount());
addBodyPart(mbp);
}
catch (MessagingException e)
{
throw new RuntimeException(e.getMessage());
}

}

/**
* @return A byte array of the complete(including the content-type of the
* whole MMSMessage Content) content.
*/
public byte[] getBinaryContent()

{
try
{
ByteArrayOutputStream byteArrayBuffer = new ByteArrayOutputStream();
// The content type of the whole content is requested and added to the output
String contentType = "Content-Type: "
+ this.getContentType() + "\r\n\r\n";
byteArrayBuffer.write(contentType.getBytes());
byteArrayBuffer.flush();
writeTo(byteArrayBuffer);
return byteArrayBuffer.toByteArray();
}
catch (IOException e)
{
throw new RuntimeException(e.getMessage());
}
catch (MessagingException e)
{
throw new RuntimeException(e.getMessage());
}
}
}

Login Login / Register Logout Logout Search Last 30 Days Topics Topics