SMS to Email Address programatically? - Windows Mobile Development and Hacking General

I did a search in the forum, and didn't see if this is mentioned, so forgive me if this has been discussed.
I am trying to programatically send an SMS to a normal email address... and I know the phone can do it (AT&T Tilt, AT&T service), as I can do it manually. My first approach (as to not start monkeying around with the MAPI stuff) is to try the SMS API (sms.h and sms.lib). I am trying to use the SmsSendMessage function. My code works great for messages to other phones, but fails with the very informative return code of E_FAIL when sending to a "normal" email address.
Is there a trick or a setting that I am missing?
Here is a code sample of what I am trying to do:
Code:
BOOL CSMSSender::Send( wchar_t *message )
{
if( message == NULL )
{
return FALSE;
}
SMS_HANDLE smsHandle;
SMS_ADDRESS source;
SMS_ADDRESS dest;
TEXT_PROVIDER_SPECIFIC_DATA textData;
SMS_MESSAGE_ID messageId;
HRESULT result = S_OK;
BOOL retVal = TRUE;
result = SmsOpen( SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smsHandle, NULL );
if( result != S_OK )
{
return FALSE;
}
// Setup source address...
dest.smsatAddressType = SMSAT_UNKNOWN;
_tcsncpy( dest.ptsAddress, GetSmsAddr( ), SMS_MAX_ADDRESS_LENGTH );
// Setup the provider information...
memset( &textData, 0, sizeof( textData ) );
textData.dwMessageOptions = PS_MESSAGE_OPTION_NONE; // No confirmation...
textData.psMessageClass = PS_MESSAGE_CLASS1;
textData.psReplaceOption = PSRO_NONE;
textData.dwHeaderDataSize = 0;
result = SmsSendMessage( smsHandle,
NULL,
&dest,
NULL,
(PBYTE) message,
_tcslen( message ) * sizeof (wchar_t),
(PBYTE) &textData,
sizeof( TEXT_PROVIDER_SPECIFIC_DATA ),
SMSDE_OPTIMAL,
SMS_OPTION_DELIVERY_NONE,
&messageId );
if( result != S_OK )
{
retVal = FALSE;
goto EXIT;
}
EXIT:
result = SmsClose( smsHandle );
if( result != S_OK )
{
retVal = FALSE;
}
return retVal;
}
You can probably guess that GetSmsAddr( ) returns a wchar_t * that is the address I am trying to send it to. When it is a phone number, works swimmingly, when it is a "normal" email address, it fails. This is, of course, a snippet of a much larger system, but the only SMS specific stuff, and the stuff that gives me the problems. So, if you wonder "why did he do it this way", probably stuff missing that would make it more clear.
If the answer is to go swimming in the mess that is MAPI, then so be it... but would like to know if there is an easier answer before I put on my trunks...
Take Care,
Wicked96SS

Found the solution... I feel dumb... It is actually pretty easy. The provider is the one that does the conversion from SMS to "normal" email. And you have to send the SMS to the email gateway. The SMS has to be specially formatted. Here is a non comprehensive list of the formats expected by certain vendors:
Format (Carrier;SMS to Email Gateway Number;Text Format)
AT&T (Formerly Cingular) USA;111 or 121;emailaddress (subject) text
CTI (Argentina);6425;emailaddress (subject) text
Swisscom Mobile AG (only Switzerland);555;<emailaddress> <subject>/<text>
T-Mobile Austria http://t-mobile.at;6761;<emailaddress> <text>
T-Mobile (USA);500;<emailaddress> / <subject> / <text>
Anyhow, still looking for Verizon and some others, but i am sure they are simple.
So, if configured like that, and sent to the correct number, I do get SMS messages to normal email accounts.
Code snippet for AT&T
Code:
result = SmsOpen( SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smsHandle, NULL );
if( result != S_OK )
{
return SMS_INIT_FAILED;
}
// Setup source address...
dest.smsatAddressType = SMSAT_UNKNOWN;
_tcsncpy( dest.ptsAddress, L"111", SMS_MAX_ADDRESS_LENGTH );
// Setup the provider information...
memset( &textData, 0, sizeof( textData ) );
textData.dwMessageOptions = PS_MESSAGE_OPTION_NONE; // No confirmation...
textData.psMessageClass = PS_MESSAGE_CLASS1;
textData.psReplaceOption = PSRO_NONE;
textData.dwHeaderDataSize = 0;
std::wstring body;
body = L"[email protected](Hi!)Here is the body";
result = SmsSendMessage( smsHandle,
NULL,
&dest,
NULL,
(PBYTE) body.c_str( ),
_tcslen( body.c_str( ) ) * sizeof (wchar_t),
(PBYTE) &textData,
sizeof( TEXT_PROVIDER_SPECIFIC_DATA ),
SMSDE_OPTIMAL,
SMS_OPTION_DELIVERY_NONE,
&messageId );

Question on Normal Emails
I found your posting and it works great for sending sms messages to cell phone emails.
I found this link that shows the other gateways you were looking for.
http://en.wikipedia.org/wiki/SMS_gateways
My question is did you ever get this to work to send emails to network email address like [email protected]
let me know if you have any suggestions.
Thanks in Advance
ColoradoGene

hello ColoradoGene! Sorry for the time it took to respond, but yes, I have been able to send SMS messages to email addresses... the message has to be formatted correctly. The source code in my post (#2) will work for AT&T.
What problems are you actually having?

Related

GPRS Connection Issues

Hi All,
My app is required to update certain information to my server every 15mins or so. This data is being successfully posted, however on reviewing my phone bill, the code is forcing a new GPRS connection with each post.
I use the ConnectionManager API to get a handle to the optimal/current connection:
Code:
DWORD dwCurrentStatus;
ConnMgrConnectionStatus(hConnection, &dwCurrentStatus);
if (dwCurrentStatus != CONNMGR_STATUS_CONNECTED){
ConnMgrEstablishConnectionSync(&sCI, &hConnection, 30000, &dwStatus);
}
// Make outgoing internet connection.
hInternetSession = InternetOpen(TEXT("My App"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
// Connect to the server
hServerSession = InternetConnect(hInternetSession, szServer, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, NULL, NULL);
if(hInternetSession == NULL || hServerSession == NULL){
return false;
}
After each post I close the internet handle ( I am fairly sure this shouldn't drop the GPRS connection):
Code:
InternetCloseHandle(hHttpSession);
InternetCloseHandle(hServerSession);
InternetCloseHandle(hInternetSession);
hHttpSession = NULL;
hServerSession = NULL;
hInternetSession = NULL;
On application SHUTDOWN I allow the connection to close:
Code:
ConnMgrReleaseConnection(hConnection, 0);
if(hConnection){
hConnection = NULL;
}
InternetCloseHandle(hHttpSession);
InternetCloseHandle(hServerSession);
InternetCloseHandle(hInternetSession);
hHttpSession = NULL;
hServerSession = NULL;
hInternetSession = NULL;
Has anyone else had similar problems or is aware of what I am doing wrong?
Cheers
gprs connection
i have a small app that changes gprs connection when one of them is down, but i have found that the connmgrreleaseconnection call does not work, and the current connection will not die, you may have the same problem

C# SendMessage to Ignore/Answer calls

I am in need of some help.
I need to be able to utilize the Win32 SendMessage API (via C#) to Ignore/Answer phone calls on a whim. The current test bed is Windows Mobile 5.0, and from what I have been able to gather, the program that I should be sending the message to is cprog.exe. So the question is, should I be sending anything other than the WM_LBUTTONDOWN, WM_RBUTTONDOWN events in order to do so?
Code:
public class Message
{
public const int WM_LBUTTONDOWN = 0x0201;
public const int WM_RBUTTONDOWN = 0x0204;
}
[DllImport("coredll.dll", EntryPoint = "SendMessage", CharSet = CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
...
Win32.SendMessage(pc.Handle, Win32.Message.WM_RBUTTONDOWN, 0, 0);
Well if you just want an app that will auto send a txt to a phone call that you can't answer, it's in the forums, Mobile Secretary. And yes, I believe from what your doing cprog.exe is the phone application.

PPC with Windows Mobile as Server

I have tried for some hours now to catch the problem, nowhere are good resources to read.
I have a server application running on my phone (Windows Mobile 6.1)
Binding the TCP Listener to 127.0.0.1ORT does work, if I type the URL from within the device.
Then I tried to connect via WIFI. At first: All WiFi Settings are correct, I know all IPs and pings are possible ... BUT: When I try to access the server from within the wifi network I don't get through. I've bound the listener for testing purposes to 127.0.0.1 and to the IP of my Wifi card. but nothing helped. Is there a kind of firewall or why can't I use a socket connection from PC to PPC?
This should work. I've create a remote-control program via TCP/IP and there were no issues.
Can you post the code for Bind / Listen?
radhoo said:
Can you post the code for Bind / Listen?
Click to expand...
Click to collapse
Code:
byte[] byteBuffer = new byte[1024];
string stringBuffer = null;
[COLOR="Red"] IPAddress localhost = IPAddress.Parse("0.0.0.0");
// I also tried 127.0.0.1 and the IP of my phone in WiFi
TcpListener httpDaemon = new TcpListener(localhost, 80);
httpDaemon.Start();
[/COLOR]
while (true)
{
TcpClient httpBrowser = httpDaemon.AcceptTcpClient();
NetworkStream commStream = httpBrowser.GetStream();
int i;
// Loop to receive all the data sent by the client.
while ((i = commStream.Read(byteBuffer, 0, byteBuffer.Length)) != 0)
{
stringBuffer = System.Text.Encoding.ASCII.GetString(byteBuffer, 0, i);
}
MessageBox.Show(stringBuffer);
httpBrowser.Close();
Provided your code is good, maybe check if the socket is actually listening, there's netstat tool in dotFred's task manager: http://www.dotfred.net/TaskMgr.htm
Furthermore, you can see if the traffic ever reaches your PPC with hSniffer:
http://winm-soft.atspace.com/
You don't seem to be checking any of the return values.
Have you done that?
You might be facing different conditions than when you bind to the loopback adapter.
theq86 said:
Code:
byte[] byteBuffer = new byte[1024];
string stringBuffer = null;
[COLOR="Red"] IPAddress localhost = IPAddress.Parse("0.0.0.0");
// I also tried 127.0.0.1 and the IP of my phone in WiFi
TcpListener httpDaemon = new TcpListener(localhost, 80);
httpDaemon.Start();
[/COLOR]
while (true)
{
TcpClient httpBrowser = httpDaemon.AcceptTcpClient();
NetworkStream commStream = httpBrowser.GetStream();
int i;
// Loop to receive all the data sent by the client.
while ((i = commStream.Read(byteBuffer, 0, byteBuffer.Length)) != 0)
{
stringBuffer = System.Text.Encoding.ASCII.GetString(byteBuffer, 0, i);
}
MessageBox.Show(stringBuffer);
httpBrowser.Close();
Click to expand...
Click to collapse
try other different port rather than http port = 80
mobile phone not design to be a web server.

(Solution) Enabling Exchange 2003 to receive HTML

PURPOSE
So the purpose of this thread is to explain how I got HTML working for Exchange 2003 servers which technically is not supposed to be possible This is me giving back to the community and I give full writes to use this code in whatever means necessary. I had to figure this out on my own with absolutely no help online so now I'm putting this here so no one else has to go through the hell that I did!
This means Hotmail via Activesync will also have full HTML support with this code patch I'm submitting.
First, AOSP Email is set up to request plain text emails from an Exchange 2003 server which is no good for us. First step is we need to request MIME messages which will contain the text/plain & text/html versions of an e-mail. So if a message was originally text/html then the MIME message will contain text/plain & text/html. If the original message was text/plain then the MIME message will only contain text/plain. No biggie there that's obviously ok.
EasSyncService.java
Code:
// Set the truncation amount for all classes
if (mProtocolVersionDouble >= Eas.SUPPORTED_PROTOCOL_EX2007_DOUBLE) {
s.start(Tags.BASE_BODY_PREFERENCE)
// HTML for email; plain text for everything else
.data(Tags.BASE_TYPE, (className.equals("Email") ?
Eas.BODY_PREFERENCE_HTML : Eas.BODY_PREFERENCE_TEXT))
.data(Tags.BASE_TRUNCATION_SIZE,
Eas.EAS12_TRUNCATION_SIZE)
.end();
} else {
if (className.equals("Email")) {
s.data(Tags.SYNC_MIME_SUPPORT, "2")
.data(Tags.SYNC_MIME_TRUNCATION, "7");
}
s.data(Tags.SYNC_TRUNCATION, Eas.EAS2_5_TRUNCATION_SIZE);
}
Explanation
The section in the if() block is for exchange 2007/2010 and basically is telling the Exchange server to send HTML for Email and plain text for anything else (ie: calendar events).
This says send me MIME messages for Exchange 2003
Code:
s.data(Tags.SYNC_MIME_SUPPORT, "2")
This says truncate the MIME message to 102,400 characters and is very important. If you don't set this then you WILL run into out of memory issues because some messages can be very large and since a MIME message contains duplicate copies of a message in two formats you're doubling the memory requirements.
Code:
.data(Tags.SYNC_MIME_TRUNCATION, "7");
Now let's get on to the part that will actually parse the MIME encoded message.
EmailSyncAdapter.java
Code:
public void addData (Message msg) throws IOException {
ArrayList<Attachment> atts = new ArrayList<Attachment>();
mimeAtts = new ArrayList<String>();
textBody = new StringBuffer();
htmlBody = new StringBuffer();
The new additions are mimeAtts, textBody, and htmlBody. We'll use these later in the code.
Code:
case Tags.EMAIL_MIME_DATA:
try {
MimeMessage mimeMsg = new MimeMessage(new ByteArrayInputStream(getValue().getBytes()));
if (mimeMsg.getBody() instanceof Multipart) {
MimeMultipart multipart = (MimeMultipart) mimeMsg.getBody();
parseMimeBody(multipart);
if (htmlBody != null && htmlBody.length() != 0)
msg.mHtml = htmlBody.toString();
else if (textBody != null)
msg.mText = textBody.toString();
else
msg.mText = "";
}
else {
InputStream in = mimeMsg.getBody().getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
in.close();
in = null;
String charset = MimeUtility.getHeaderParameter(mimeMsg.getContentType(), "charset");
if (charset == null)
charset = "UTF-8";
String mimeTxt = out.toString(charset);
charset = null;
out = null;
if (mimeMsg.isMimeType("text/html"))
msg.mHtml = mimeTxt;
else
msg.mText = mimeTxt;
}
} catch (MessagingException e) {}
break;
This is a new case block that I added specifically for parsing MIME encoded messages. In a nutshell I'm creating the MimeMessage object, checking if it is a multi-part message or single-part message and parsing accordingly.
Code:
if (atts.size() > 0 && mimeAtts != null) {
for(Attachment att : atts) {
for (String contentId : mimeAtts) {
if (contentId == null)
continue;
if (att.mFileName != null && contentId.contains(att.mFileName))
att.mContentId = contentId;
}
}
msg.mAttachments = atts;
}
This is really important and is still in the same method as the above two code sections. The issue is when an attachment is downloaded the content-id isn't specified. So now that we have the MIME message we can actually grab that content-id out of there and update each attachment with the correct content-id. Later in MessageView.java it will use that value to display the embedded images correctly.
Code:
private void parseMimeBody(MimeMultipart multipart) {
try {
for (int i=0; i<multipart.getCount(); ++i) {
BodyPart part = multipart.getBodyPart(i);
if (part.isMimeType("text/plain"))
textBody.append(MimeUtility.getTextFromPart(part));
else if (part.isMimeType("text/html"))
htmlBody.append(MimeUtility.getTextFromPart(part));
else if (part.isMimeType("multipart/alternative"))
parseMimeBody((MimeMultipart)part.getBody());
else
mimeAtts.add(part.getContentId());
}
}
catch (MessagingException e) {}
}
This is a new method I added which handles parsing out the message bodies from a multi-part MIME message. It uses recursion if there are embedded multi-part messages in the original multi-part message.
The last part which I won't paste here is incorporating the support for viewing MIME messages into MessageView.java. I've taken the 3 files that were modified and I'm attaching them to this e-mail. These are straight from my paid email app so there are other additions in there that someone can diff out. If I get time I'll patch these changes into AOSP email but I'm swamped 24/7 with Enhanced Email so I'd suggest someone else do it and contact me with questions.
This is the same hack that iPhone uses to enable HTML for ex2003 and once again is undocumented ANYWHERE on the net except for here by me
So... with this zip file (I don't know much about unpacking it in android- I am a winmo 6.5 user). I will be able to use hotmail via exchange server and view attachments ...etc just like an regular email client would behave?
I want to migrate to Android so bad, but I don't want to give up my hotmail account. As of now this is how I am setup on winmo 6.5:
1. PH#s (contacts with PH#s) + Calendar - Gmail synced via microsoft exchange
2. Email (Hotmail) + Email contacts - synced via windows live email client
Any advise will be greatly appreciated. Also... I would like to combine somehow all my contacts in one directory that will be synced somehow between gmail (for google voice texts and calls) and hotmail (since I use this all over my PC's and add contacts from different locations. Thank you!!!

[Q] Autodiscovery for Activesync

I recently found out that the autodiscovery process in Android's email application is incomplete. It will only query https://domain.com/autodiscover/autodiscover.xml and https://autodiscover.domain.com/autodiscover/autodiscover.xml
I know this because I checked the source.
I only have a trusted certificate for mail.mydomain.com, so I need to tell the activesync client this. The people at Microsoft thought of a way to do this, but it involves querying an SRV-record in DNS (host -t srv _autodiscover._tcp.domain.com).
This is not done by the email-client in Android.
The full procedure for autodiscovery is described here:
http://technet.microsoft.com/en-us/library/bb332063(EXCHG.80).aspx
This is the code I found on http://android.git.kernel.org
EasSyncService.java
Code:
// There are up to four attempts here; the two URLs that we're supposed to try per the
// specification, and up to one redirect for each (handled in postAutodiscover)
// Note: The expectation is that, of these four attempts, only a single server will
// actually be identified as the autodiscover server. For the identified server,
// we may also try a 2nd connection with a different format (bare name).
// Try the domain first and see if we can get a response
HttpPost post = new HttpPost("https://" + domain + AUTO_DISCOVER_PAGE);
setHeaders(post, false);
post.setHeader("Content-Type", "text/xml");
post.setEntity(new StringEntity(req));
HttpClient client = getHttpClient(COMMAND_TIMEOUT);
HttpResponse resp;
try {
resp = postAutodiscover(client, post, true /*canRetry*/);
} catch (IOException e1) {
userLog("IOException in autodiscover; trying alternate address");
// We catch the IOException here because we have an alternate address to try
post.setURI(URI.create("https://autodiscover." + domain + AUTO_DISCOVER_PAGE));
// If we fail here, we're out of options, so we let the outer try catch the
// IOException and return null
resp = postAutodiscover(client, post, true /*canRetry*/);
}
I already wrote the coder of Android's email application (Marc Blank) an email, but I didn't get a reply.
I am not a java-developer nor do I have write access for Android's source code (obviously). Is there anyone here on this board who can help me to get this full procedure incorporated into Android's code?

Categories

Resources