API for MMS in vb.net

API for MMS in vb.net SearchSearch
Author Message
Michael Johns
New member
Username: Michaelilaga

Post Number: 1
Registered: 02-2012
Posted on Wednesday, February 08, 2012 - 02:03 pm:   

I am currently developing a vb.net application that will be able to send a MMS to phones. I am using a gprs modem and i've already tried using your web interface for MMS sending and it works fine. but I want to use that capability in my vb.net. Is there an API for that? If there is none, then how will I be able to send an MMS from my application using your service? I hope you can help me with this. By the way, the file to be attached to the MMS message will be from my local hard drive. Thanks.
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 3767
Registered: 08-2008
Posted on Wednesday, February 08, 2012 - 11:04 pm:   

Hi Michael,

I don't know VB.NET, but can you use C#.NET?

Basically, the process of sending an MMS is to perform an HTTP POST using a MIME content type of multipart/form-data.

This is commonly referred to as "HTTP File Upload".

More information on the NowSMS specific format for this type of HTTP POST can be found here:

http://www.nowsms.com/sending-mms-messages-with-nowsms

Now back to C#.NET.

There's a great C#.NET HTTP File Upload library at:

http://aspnetupload.com/Upload-File-POST-HttpWebRequest-WebClient-RFC-1867.aspx

A direct link to download the library is here (you just need UploadHelper):

http://aspnetupload.com/AspNetUploadSamples.zip

In case that link doesn't work in the future, here is another copy of the file:

application/x-zip-compressedAspNetUploadSamples.zip
AspNetUploadSamples.zip (388.7 k)


I wrote the following sample code using that library to send an MMS message using that library:


// Set the following variables as appropriate for your system.

// URL that points to NowSMS web interface
Uri url = new Uri("http://127.0.0.1:8800/");

// Valid username/password for account defined in NowSMS under "SMS Users".
String username = "testuser";
String password = "testpass";

// Images & Files to be included in the message.
// First parameter is filename and path.
// Second parameter must be MMSFILE
// Third parameter should be MIME type

UploadFile[] files = new UploadFile[]
{
new UploadFile("f:\\temp\\image1.png", "MMSFILE", "image/png"),
new UploadFile("f:\\temp\\image2.jpg", "MMSFILE", "image/jpeg"),
};

// Create additional form parameters for sending MMS
NameValueCollection form = new NameValueCollection();

// "PhoneNumber" variable contains recipient phone number
form["PhoneNumber"] = "9999999999";
// "MMSFROM" variable contains sender phone number or address (Note: Ignored when sending via modem)
form["MMSFROM"] = "9999999999";
// "MMSSUBJECT" variable contains subject line for message
form["MMSSUBJECT"] = "test subject";
// "MMSTEXT" variable contains test to appear in message (optional)
form["MMSTEXT"] = "This is a test message";

// Send the request to NowSMS, creating an HttpWebRequest and
// then use HttpUploadHelper to send files in multipart/form-data format
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

var credCache = new CredentialCache();
credCache.Add(url, "Basic", new NetworkCredential(username, password));
req.Credentials = credCache;

HttpWebResponse resp = HttpUploadHelper.Upload(req, files, form);

// Read the HTTP response and echo to console
using (Stream s = resp.GetResponseStream())
using (StreamReader sr = new StreamReader(s))
{
string response = sr.ReadToEnd();
System.Console.WriteLine(response);
}


The discussion board software probably mangled my code a little bit, so I've also uploaded it as a text attachment.

text/plainsendmms.c#
sendmms.c#.txt (2.4 k)



--
Des
NowSMS Support
Michael Johns
New member
Username: Michaelilaga

Post Number: 2
Registered: 02-2012
Posted on Thursday, February 09, 2012 - 02:42 pm:   

I've converted this to vb.net and it worked perfectly! thank you very much. I really appreciate your help Des! Thanks! :)
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 3768
Registered: 08-2008
Posted on Thursday, February 09, 2012 - 02:44 pm:   

Would you mind sharing the VB.NET conversion? (I have no idea how to convert like this...)

Thanks!
Michael Johns
New member
Username: Michaelilaga

Post Number: 3
Registered: 02-2012
Posted on Thursday, February 09, 2012 - 03:03 pm:   

Here is the code in vb.net. I created a window with a single button:

text/plainSending MMS in VB.NET
MainProject.txt (2.9 k)


These are the DLL files that I've converted from the your code. Just add references to this:

application/octet-streamDLL Files
DLL.rar (20.4 k)


if you want the whole project I made, here is the project:

application/octet-streamProject
Prorotype.rar (495.2 k)


Thanks DES!
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 3772
Registered: 08-2008
Posted on Friday, February 10, 2012 - 04:06 pm:   

Michael,

Thanks for sharing the VB.Net translation.

We've updated our examples to include that information.

For others who are interested, the following links may be helpful:

Send MMS Message with VB .NET
Send MMS Message with C# .NET

--
Des
NowSMS Support
Michael Johns
New member
Username: Michaelilaga

Post Number: 4
Registered: 02-2012
Posted on Tuesday, February 14, 2012 - 04:26 am:   

When I connect two gsm modems to my laptop and try to use nowsms MMS service I get this error:
"Webport already in use"

How do I solve that? thanks
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 3782
Registered: 08-2008
Posted on Tuesday, February 14, 2012 - 07:15 pm:   

I replied to your other posting on this new question: http://support.nowsms.com/discus/messages/485/70836.html
farhan
New member
Username: Paan

Post Number: 1
Registered: 05-2013
Posted on Monday, May 13, 2013 - 12:29 pm:   

micheal john can you please mail to me the DLL file

shutdefarkup@gmail.com
Michael Johns
New member
Username: Michaelilaga

Post Number: 11
Registered: 02-2012
Posted on Monday, May 13, 2013 - 12:40 pm:   

Hi, farhan.

You may just right-click on the link above for the DLL files then save the link as .rar file for you to be able to open it.
farhan
New member
Username: Paan

Post Number: 2
Registered: 05-2013
Posted on Monday, May 13, 2013 - 12:45 pm:   

hi, Micheal

how to install the DLL file in your project
farhan
New member
Username: Paan

Post Number: 3
Registered: 05-2013
Posted on Tuesday, May 14, 2013 - 07:54 pm:   

where can i get these
Imports ClassLibrary1
Imports ClassLibrary1.Krystalware
Imports ClassLibrary1.Krystalware.UploadHelper
Imports ClassLibrary1.Krystalware.UploadHelper.HttpUploadHelper
Imports ClassLibrary1.Krystalware.UploadHelper.MimePart
Imports ClassLibrary1.Krystalware.UploadHelper.StreamMimePart
Imports ClassLibrary1.Krystalware.UploadHelper.StringMimePart
Imports ClassLibrary1.Krystalware.UploadHelper.UploadFile
Imports System.Collections.Specialized
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 4475
Registered: 08-2008
Posted on Tuesday, May 14, 2013 - 09:15 pm:   

The Krystalware UploadHelper library download is referenced in the second message on this thread ... aspnetupload web site.