Topic Keywords: API, Java, Sending MMS
A Java example for sending MMS messages via NowSMS has been posted at the following link:
https://nowsms.com/download/sendmms.java.txt
This class supports all of the MMS related parameters available in NowSMS, most of which are described later in this posting.
For a related PHP script, please see:
https://nowsms.com/nowsms-php-example-send-mms-message
To use this Java class, begin by creating a new sendmms object, specifying the address of the NowSMS server, and a valid username and password for a user account (“SMS Users”) on the NowSMS Server.
sendmms mms = new sendmms (“http://127.0.0.1:8800/”, “test”, “test”);
The addparameter method is used to build the MMS message object.
Start by specifying a recipient using the “PhoneNumber” parameter (this can be a comma delimited list of recipients):
mms.addparameter (“PhoneNumber”, “+9999999999”);
Next, add any desired MMS header parameters, such as the message subject using the “MMSSubject” parameter, or an optional text part of the message using the “MMSText” parameter:
mms.addparameter (“MMSSubject”, “This a a test message”);
mms.addparameter (“MMSText”, “test message”); // Optional
Next, add the file objects for the MMS content using the “MMSFile” parameter.
mms.addparameter (“MMSFile”, new File(“f:\\temp\\test.jpg”));
mms.addparameter (“MMSFile”, new File(“f:\\temp\\test2.jpg”));
(Note: Remember to escape the “\” character as “\\” in your Java code.)
The send method submits the MMS message to NowSMS.
mms.send ();
The send method returns a string containing the MMS Message ID assigned for the submitted messages, in the following format:
MMSMessageID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Note that a try/catch exception handler must be added around the object. Here’s a complete example:
try {
sendmms mms = new sendmms (“http://127.0.0.1:8800/”, “test”, “test”);
mms.addparameter (“PhoneNumber”, “+9999999999”);
mms.addparameter (“MMSSubject”, “This a a test message”);
mms.addparameter (“MMSText”, “test message”); // Optional
mms.addparameter (“MMSFile”, new File(“f:\\temp\\test.jpg”));
mms.addparameter (“MMSFile”, new File(“f:\\temp\\test2.jpg”));
mms.send ();
}
catch(IOException e) {
System.out.println(“unable to create new url: “+e.getMessage());
}
The mms.addparameter method can be used to specify any NowSMS URL parameter that is valid for sending an MMS message. For example … here is an incomplete list of additional parameter fields that can be specfied using the mms.addparameter.
“MMSDeliveryReport” – “Delivery Report” specifies whether or not a delivery report is requested for the message. Set to “Yes” to request a delivery report. Note that any delivery report would be directed back to the phone number or e-mail address specified in the “MMSFrom” address.
“MMSReadReport” – “Read Report” specifies whether or not a read receipt is requested for the message. Note that the receiving client may choose not to send a read receipt. Any read receipt report would be directed back to the phone number or e-mail address specified in the “MMSFrom” address.
“MMSPriority” – “Priority” is a user defined priority to be associated with the message. Generally, any priority definition associated with the message is ignored by the underlying transport, but the receiving client may decide to display messages differently based upon this priority setting.
“MMSMessageClass” – “Message Class” is an attribute defined in the MMS specifications. “Personal” is the message type that is used for standard user-to-user communications. Other defined message classes that are supported by this parameter include: “Informational” and “Advertisement”.
“MMSWAPPush” – Set to “Yes” to indicate that the message being sent should be sent as an “Multimedia WAP Push” message instead of as an MMS message.
It is also possible to specify forward locking and DRM constraints to be applied against the content of the MMS message. Forward locking and DRM constraints apply to non-text parts of the MMS message (i.e., in a forward locked message, text could still be forwarded, but images or video could not). Please note that not all devices support forward locking and DRM constraints, therefore use these parameter settings only after testing thoroughly with mobile phones used by your message recipients.
“MMSForwardLock” – Forward locking is the most basic level of DRM (Digital Rights Management). When “Forward Lock” is set to “Yes”, this indicates that the receiving device should not allow any non-text objects in the message to be forwarded off of the device. The device may allow the user to extract pictures, videos or sounds from the message and save them on the phone. However, any such objects remain forward locked, such that they cannot be forwarded to another user or transferred to another device. (IMPORTANT NOTE: NOT ALL DEVICES SUPPORT FORWARD LOCK, WHEN NOT SUPPORTED THE CONTENT WILL APPEAR AS GARBAGE OR MAY BE REJECTED BY THE OPERATOR MMSC.)
“DRMRestrict” – Beyond forward locking, More advanced DRM (Digital Rights Management) restrictions can be applied to limit the number of times that the user can access an object, or start and end dates can be specified to limit how long the user can access an object.These advanced DRM restrictions can be applied by setting “DRMRestrict” to “Yes”. When this setting is enabled, forward lock is also implied, and the value of the “MMSForwardLock” setting is ignored. (IMPORTANT NOTE: NOT ALL DEVICES SUPPORT DRM RESTRICTIONS, WHEN NOT SUPPORTED THE CONTENT WILL APPEAR AS GARBAGE OR MAY BE REJECTED BY THE OPERATOR MMSC.)
“DRMRestrictTextXML” – “Yes” specifies that the rights object should be encoded in text XML format. “No” specfies that the rights object should be encoded in binary XML format. The default is “No”.
When DRM Restrictions are specfied, it is generally necessary to specify one or more DRM Permissions and one or more DRM Constraints regarding the MMS message content.
DRM Permissions specify what types of access are allowed against the objects in a message that is protected with DRM.
For example, an audio or video object requires “Play” permission before the user can access it. An image requires “Display” permission before the user can access it, and it requires “Print” permission if the user is to be allowed to print the image to a printer , perhaps over Bluetooth. An application requires “Execute” permission before the user can make use of the application. In all cases, the forward locking is assumed, so that the user is not allowed to forward or transfer the object from the device.
If you are sending multiple types of objects in the MMS message, specify all permissions that are required for the different types of objects that are being sent.
“DRMPermissionPlay” – Set to “Yes” to enable DRM “Play” Permission.
“DRMPermissionDisplay” – Set to “Yes” to enable DRM “Display” Permission.
“DRMPermissionExecute” – Set to “Yes” to enable DRM “Execute” Permission.
“DRMPermissionPrint” – Set to “Yes” to enable DRM “Print” Permission.
DRM Constraints specify constraints with regard to how long a DRM protected object object should remain accessible to the user.”DRMConstraintCount” – “# of Accesses (count)” specifies the the user can only access the DRM protected object this number of times before access is no longer allowed.
“DRMConstraintStart” – “Start Date (yyyy-mm-dd)” specifies that the user will not be allowed to access the DRM protected object until on or after the specified date. (Note that you must specify the date in yyyy-mm-dd format, e.g., 2008-12-24.)
“DRMConstraintEnd” – “End Date (yyyy-mm-dd)” specifies that the user will not be allowed to access the DRM protected object after the specified date. (Note that you must specify the date in yyyy-mm-dd format, e.g., 2008-02-24.)
“DRMConstraintInterval” – “# of Days (interval)” specifies that the user will be allowed to access the DRM protected object for this number of days after initial receipt of the object. The user can either enter a number of days here, or they can enter any valid value defined for the “” element in the OMA DRM Rights Expression Language specification. For example, P2Y10M15DT10H30M20S represents a duration of 2 years, 10 months, 15 days, 10 hours, 30 minutes and 20 seconds.
For comments and further discussion, please click here to visit the NowSMS Technical Forums (Discussion Board)...
One Response to “Send MMS from Java (or JSP)”
thanks for code