Skip to main content
JDBird1000
Known Participant
July 31, 2009
Answered

Sending mail from flash

  • July 31, 2009
  • 2 replies
  • 1374 views

Ok with much help from Kglad Ned and Raymond i have a working ASP file that sends a email but as is it gets all input from HTML form i have tryed to revise it to get information from flash but nothing happens The origenal asp is as follows...

<% Option Explicit %>
<%
'Declare variables
Dim sMsg
Dim sTo
Dim sFrom
Dim sSubject
Dim sTextBody
Dim sHTMLBody

Dim confSendUsing
Dim confServer
Dim confPort

confSendUsing = 2
confServer = "smtp.tde.com" 'SMTP server name or Ip address
confPort=25

'Get data from previous page
sTo = Request("sTo")
sFrom = Request("sFrom")
sSubject = Request("sSubject")
sTextBody = Request("sTextBody")
sHTMLBody = Request("sHTMLBody")

'Only run this if it's not the first time
If Request.Form("Submit") <> "" Then

Dim objMail
'Create the mail object
Set objMail = Server.CreateObject("CDO.Message")
'Set key properties
objMail.From = sFrom
objMail.To = sTo
objMail.Subject= sSubject
objMail.TextBody = sTextBody
objMail.HTMLBody = sHTMLBody


objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=confSendUsing
'Name or IP of remote SMTP server
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")= confServer
'Server port
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=confPort
objMail.Configuration.Fields.Update


'Send the email
objMail.Send
'Set sMsg which will be used later
sMsg = "Your message was sent to: " & sTo

'Clean-up
Set objMail = Nothing

End If
%>
<html>
<head><title>SendMail</title></head>
<body>
<form action="<%=Request.ServerVariables("PATH_INFO")%>" method="post">
  <table>
    <tr>
      <td>Send To:</td>
      <td><input type="text" name="sTo" value="<%=sTo%>"></td>
    </tr>
    <tr>
      <td>Send From:</td>
      <td><input type="text" name="sFrom" value="<%=sFrom%>"></td>
    </tr>
   <tr>
      <td>Message Subject:</td>
      <td><input type="text" name="sSubject" value="<%=sSubject%>"></td>
    </tr>
    <tr>
      <td>Message Text Body:</td>
      <td><textarea cols="60" rows="5" name="sTextBody">
         <%=sTextBody%></textarea></td>
    </tr>
    <tr>
      <td>Message HTML Body:</td>
      <td><textarea cols="60" rows="5" name="sHTMLBody">
         <%=sHTMLBody%></textarea></td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="submit" name="Submit" value="Submit"></td>
    </tr>
  </table>
  <hr>
  <%=sMsg%>
  </form>
</body>
</html>

THIS WORKS PERFECTLY

i have tryed to omit the HTML like this:

<% Option Explicit %>
<%
'Declare variables
Dim sMsg
Dim sTo
Dim sFrom
Dim sSubject
Dim sTextBody
Dim sHTMLBody

Dim confSendUsing
Dim confServer
Dim confPort

confSendUsing = 2
confServer = "smtp.tde.com" 'SMTP server name or Ip address
confPort=25

'Get data from previous page
sTo = Request("sTo")
sFrom = Request("sFrom")
sSubject = Request("sSubject")
sTextBody = Request("sTextBody")
sHTMLBody = Request("sHTMLBody")

'Only run this if it's not the first time
If Request.Form("Submit") <> "" Then

Dim objMail
'Create the mail object
Set objMail = Server.CreateObject("CDO.Message")
'Set key properties
objMail.From = sFrom
objMail.To = sTo
objMail.Subject= sSubject
objMail.TextBody = sTextBody
objMail.HTMLBody = sHTMLBody


objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=confSendUsing
'Name or IP of remote SMTP server
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")= confServer
'Server port
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=confPort
objMail.Configuration.Fields.Update


'Send the email
objMail.Send
'Set sMsg which will be used later
sMsg = "Your message was sent to: " & sTo

'Clean-up
Set objMail = Nothing

End If
%>

and contact it with this flash AS3:

stop();
emailfrom_txt.text = "someone@somewhere.com";
emailto_txt.text = "someone@somewhere.com";
emailbody_txt.text = "";
emailsubject_txt.text = "";
htmlbody_txt.text = "";

submit_btn.addEventListener(MouseEvent.CLICK, sendInfo);

var emailfrom = emailfrom_txt.text;
var emailto = emailto_txt.text;
var emailsubject = emailsubject_txt.text;
var emailbody = emailbody_txt.text;
var htmlbody = htmlbody_txt.text;
 
function sendInfo (e:MouseEvent):void{
      var varSend:URLRequest = new URLRequest("mailer4.asp");
      varSend.method = URLRequestMethod.GET;
   var urlVar:URLVariables=new URLVariables();
   urlVar.sFrom = emailfrom;
      urlVar.sTo = emailto;
   urlVar.sSubject = emailsubject;
   urlVar.sTextBody = emailbody;
   urlVar.sHTMLBody = htmlbody;
   varSend.data=urlVar;
   var urlLDR:URLLoader=new URLLoader();
   urlLDR.addEventListener(Event.COMPLETE,completeF);
   urlLDR.load(varSend);
}

function completeF(e:Event){
trace("COMPLETE");
trace(URLLoader(e.target).data);
trace (emailto, emailfrom, emailsubject, emailbody, htmlbody);
}

what did i miss?

This topic has been closed for replies.
Correct answer

made all changes now nothing happens...

AS3:

stop();

submit_btn.addEventListener(MouseEvent.CLICK, sendInfo);
var emailfrom = emailfrom_txt.text;
var emailto = emailto_txt.text;
var emailsubject = emailsubject_txt.text;
var emailbody = emailbody_txt.text;
var htmlbody = htmlbody_txt.text;
 
function sendInfo (e:MouseEvent):void{
      var varSend:URLRequest = new URLRequest("mailer4.asp");
      varSend.method = URLRequestMethod.POST;
   var urlVar:URLVariables=new URLVariables();
      urlVar.sFrom = emailfrom;
      urlVar.sTo = emailto;
      urlVar.sSubject = emailsubject;
      urlVar.sTextBody = emailbody;
      urlVar.sHTMLBody = htmlbody;
      varSend.data=urlVar;
      var urlLDR:URLLoader=new URLLoader();
      urlLDR.addEventListener(Event.COMPLETE,completeF);
      urlLDR.load(varSend);
}

function completeF(e:Event){
trace("COMPLETE");
trace(URLLoader(e.target).data);
trace (emailto, emailfrom, emailsubject, emailbody, htmlbody);
}

is there somthing that can check whats happening?

ASP:

<% Option Explicit %>
<%
'Declare variables
Dim sMsg
Dim sTo
Dim sFrom
Dim sSubject
Dim sTextBody
Dim sHTMLBody

Dim confSendUsing
Dim confServer
Dim confPort

confSendUsing = 2
confServer = "smtp.tde.com" 'SMTP server name or Ip address
confPort=25

'Get data from previous page
sTo = Request.Item ("sTo")
sFrom = Request.Item ("sFrom")
sSubject = Request.Item ("sSubject")
sTextBody = Request.Item("sTextBody")
sHTMLBody = Request.Item ("sHTMLBody")

'Only run this if it's not the first time
If Request.Form("Submit") <> "" Then

Dim objMail
'Create the mail object
Set objMail = Server.CreateObject("CDO.Message")
'Set key properties
objMail.From = sFrom
objMail.To = sTo
objMail.Subject= sSubject
objMail.TextBody = sTextBody
objMail.HTMLBody = sHTMLBody


objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=confSendUsing
'Name or IP of remote SMTP server
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")= confServer
'Server port
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=confPort
objMail.Configuration.Fields.Update


'Send the email
objMail.Send
'Set sMsg which will be used later
sMsg = "Your message was sent to: " & sTo

'Clean-up
Set objMail = Nothing

End If
%>


That script sends the mail only if a submit button was pressed - as would be the case in an html form.

Remove these 2 lines:

If Request.Form("Submit") <> "" Then

End If

... but leave what's between the lines

2 replies

kglad
Community Expert
Community Expert
July 31, 2009

you're using "post" in your form and "GET" in flash.  try:

stop();
emailfrom_txt.text = "someone@somewhere.com";
emailto_txt.text = "someone@somewhere.com";
emailbody_txt.text = "";
emailsubject_txt.text = "";
htmlbody_txt.text = "";

submit_btn.addEventListener(MouseEvent.CLICK, sendInfo);

var emailfrom = emailfrom_txt.text;
var emailto = emailto_txt.text;
var emailsubject = emailsubject_txt.text;
var emailbody = emailbody_txt.text;
var htmlbody = htmlbody_txt.text;
 
function sendInfo (e:MouseEvent):void{
      var varSend:URLRequest = new URLRequest("mailer4.asp");
     varSend.method = URLRequestMethod.POST;
   var urlVar:URLVariables=new URLVariables();
   urlVar.sFrom = emailfrom;
      urlVar.sTo = emailto;
   urlVar.sSubject = emailsubject;
   urlVar.sTextBody = emailbody;
   urlVar.sHTMLBody = htmlbody;
   varSend.data=urlVar;
   var urlLDR:URLLoader=new URLLoader();
   urlLDR.addEventListener(Event.COMPLETE,completeF);
   urlLDR.load(varSend);
}

function completeF(e:Event){
trace("COMPLETE");
trace(URLLoader(e.target).data);
trace (emailto, emailfrom, emailsubject, emailbody, htmlbody);
}

JDBird1000
Known Participant
July 31, 2009

Am I getting that error because im not converting the text inputs to string?

Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: http://www.teamwl.com/quiz/mailer4.asp

at MailASPtest_fla::MainTimeline/sendInfo()

July 31, 2009

On the server side, if you use the GET method to send your data, you need to get the values from the Request.QueryString collection.

On the other hand, if you use POST, you should use the Request.Item collection.

sTo = Request.QueryString("sTo")
sFrom = Request.QueryString("sFrom")
sSubject = Request.QueryString("sSubject")
sTextBody = Request.QueryString("sTextBody")
sHTMLBody = Request.QueryString("sHTMLBody")

JDBird1000
Known Participant
July 31, 2009

This time on the web it throws this error:

Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: http://www.teamwl.com/quiz/mailer4.asp

at MailASPtest_fla::MainTimeline/sendInfo()

July 31, 2009

Click the link http://www.teamwl.com/quiz/mailer4.asp

Should be

sTo = Request.Item("sTo")