0

I have run into some problems with emailing a file from flex. I currently use the code below. If bodyVar is fewer than 1967 then the email is populated fine. When i call this code an Outlook message opens containing whatever is in bodyVar. If it is more than 1967 then it opens with a blank page.

var mailMsg:URLRequest = new URLRequest("mailto:");
var variables:URLVariables = new URLVariables();
variables.subject = subVar;
variables.body = bodyVar;
mailMsg.data = variables;
mailMsg.method = URLRequestMethod.GET;
navigateToURL(mailMsg, "_self");

I am using Firefox and I presume this 1967 is coming from that. If I used IE then the email does not even open.

Does anyone know of a way of sending an email in flex which allows me to send a lot of text? I am not bothered by formatting or images etc. I just need to be able to send text

Thanks

EDIT

I have just found this bit of code that shows another way without using URLVariables object. I presume the limitation here is in http

var s:String = "";
s += "mailto:";
s+= sendTo.text;
s+= "?";
s+= "subject=";
s+= subjectVar;
s+= "&";
s+= "body=";
s+= bodyVar;
navigateToURL(new URLRequest(s));

EDIT 2 To be clear I want to open a new email message using the user's email client. So if they have outlook installed I would like an Outlook msg opened containing text that should be sent.

RNJ
  • 15,272
  • 18
  • 86
  • 131
  • 1
    As I know, maximum length of URL supported by browser is not specified in any standards, so all browsers use this fact as an excuse for their limitations. So...did you try using POST instead of GET? What about sending mail directly with SMTP, without opening client's mail application? – user1875642 Dec 31 '12 at 14:56
  • Thanks for the reply @user1875642 I tried POST and then nothing was sent to the the email. Sending email with SMTP is an idea but my problem is that I want the users to input the email addresses. I could add another popup for them to do this but ideally I wanted the email there so the user could amend it as they wished – RNJ Dec 31 '12 at 15:32
  • You can also try javascript workaround through ExternalInteface, like `parent.location=mailToUrl` – user1875642 Dec 31 '12 at 17:09
  • @user1875642 Thanks for this hint. Ive had a quick look at ExternalInteface but can quite see what you mean. Can you explain a bit more please – RNJ Jan 02 '13 at 15:04
  • `ExternalInterface.call('function(){ parent.location="mailto:microsoft@gmail.com?subject=nothing&body=body"}');` but it seems that it's also limited. However, javascript is more common than flex, so there are lots of articles about sending mails from js. For example, you can try MAPI protocol. – user1875642 Jan 03 '13 at 08:02
  • I'm unclear if you are trying to send email from a Flex app or just trying to launch an email client on your users machine, so they can send the email. Can you clarify? I don't think there will be anything you can do to get around the URL size limit of the browser; but you should be able to send much larger data chunks to a server. – JeffryHouser Jan 03 '13 at 16:07
  • `GET` query string has a limited capacity. Check http://stackoverflow.com/q/4473959 and http://stackoverflow.com/q/2411385 for similar questions. – inhan Jan 04 '13 at 02:13
  • did you look at my answer? It has all the info you need. – Jason Reeves Jan 09 '13 at 06:28
  • @JasonReeves Yep I didnt - thanks for the link - that was really useful – RNJ Jan 09 '13 at 08:56

2 Answers2

1

As a combination of ideas:

  1. Display the message text in a flex panel/window with functions to select addresses, edit text, etc.
  2. Take this info and send it to a server-side object (PHP email, MAPI, etc) for delivery

In essence you create / edit the message in flex where you can see it all. Then you use a more robust method for sending it.

BTW: Server-side doesn't necc imply that you have a server - rather that you have some functionality outside of flex for the actual message creation and delivery.

ethrbunny
  • 10,379
  • 9
  • 69
  • 131
1

I ran into this exact thing a while back. After some deep digging I discovered the issue:

The problem is that Outlook (like Internet Explorer) has a URI character limit of 2048 characters (total length which is why you are getting cut off). Outlook also has a max recipient length of 75 recipients.

So your hard limit is coming from outlook. I would assume that the reason it performs differently when Firefox is set as the default browser is because firefox supports WAY more characters than internet explorer. So it will make it through firefox... then die at outlook. But when you use IE, it dies at IE since they have the same small char limit.

The reason it shows up blank is because once one of these limits are hit, the browser converts mailto:long string into mailto:"" (an empty string).

I would recommend:

a) forcing the character limits in the UI to stay small b) using a server side script to send the emails instead.

Here is a link that shows all of the different browsers and email clients and their corresponding character limits Link to Limits Page

Jason Reeves
  • 1,716
  • 1
  • 10
  • 13