How to Make a button send an email using AS3 automatically - actionscript-3

I am working in actionscript 3.0 and am making a website!
In my website, I want to make a button that sends an email using a click of button and I don't want it to open their mail client, instead just send it.
I am currently using the "mailto" function but would like to know how to make it send automatically, or what else I can use to achieve that.
Here is a snippet of my code:
function submitPoll(e:MouseEvent):void {
//sending the email stuff
var request:URLRequest = new URLRequest("mailto:name#hotmail.com"+"?subject=Subject"+"&body= Hello world ");
navigateToURL(request, "_blank");
request.method = URLRequestMethod.POST;
//other
Submit_btn.x = -100;
pollUsed = true;
thanks_txt.x = 849;
thanks_txt.y = 656;
}

The situation with Flash is more or less the same as the situation with HTML when it comes to sending email. You have 2 options:
Pop open the email client on the users machine using mailto as you are doing.
Send a POST or GET request to a server which can send the email on your behalf.
What you want to do is number 2 so that means you need access to a server capable of sending mail that can also receive GET/POST requests. If you have script access to your webserver you can undoubtedly find a free online script that will allow you to send emails. For example:
PHP
Python
Ruby
Perl
ASP
How you send the information to the script will depend on what variables the script requires you to send. From ActionScript you will probably want to use URLLoader:
const SCRIPT_URL:String = "http:// .... your server ... / ... script file ...";
var request:URLRequest = new URLRequest(SCRIPT_URL);
var variables:URLVariables = new URLVariables();
// these depend on what names the script expects
variables.email = "name#hotmail.com";
variables.subject = "Subject";
variables.body = "Hello World";
request.data = variables;
// depends if the script uses POST or GET
// adjust accordingly
request.method = URLRequestMethod.POST;
var urlLoader:URLLoader = new URLLoader();
loader.load(request);

I think its a case of doing a URLRequest to another PHP file. Send the values of the textfield to the PHP file and process the email that way.
I don't have any code to hand, but this is what I did when I was doing the same. Hope this helps... and don't forget to validate :)

Related

How to take a text field and set it as the description

I am working in google Apps Scripts, specifically with Google Drive. I am trying to make an application that when the user types in text into the text field, the program takes the text and sets its description using setDescription(). Everything is working fine, i just cannot figure out how to take whatever text the user enters and set it as the description.
Thanks in advance
First get the value of input
Example code from this SO answer:
var textbox = app.createTextBox().setName("textboxName");
var buttonHandler = app.createServerHandler("updateLabelText").addCallbackElement(textbox);
var button = app.createButton("Click me").addClickHandler(buttonHandler);
var label = app.createLabel().setId("label");
Then in your function:
function updateLabelText(e) {
var app = UiApp.getActiveApplication();
app.getElementById("label").setText(e.parameter.textboxName);
return app;
}
Assign a Simple Trigger
doGet(e) runs when a user visits a web app or a program sends an HTTP GET request to a web app.
doPost(e) runs when a program sends an HTTP POST request to a web app.
Set Text as Description
// Trash every untitled spreadsheet that hasn't been updated in a week.
var files = DriveApp.getFilesByName('Untitled spreadsheet');
files.setDescription(description)

Google Script, Import HTML data

I'm trying to create a personal notifier whenever a certain website contains the word 'Indian' the script should email me.
For some reason I cannot find a script function that would import HTML data,
Is there such a function?
Yes, you can perform a URL fetch:
https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#fetch(String)
Just like Harold said, you can perform a URL fetch:
var output = UrlFetchApp.fetch("https://raw.githubusercontent.com/####");
var form = HtmlService.createHtmlOutput(output.getContentText());
SpreadsheetApp.getUI().showModalDialog(form, "Fetched HTML");
You can otherwise fetch a website using the same tactic, for example:
var output = UrlFetchApp.fetch("https://www.google.com");
var form = HtmlService.createHtmlOutput(output.getContentText());
SpreadsheetApp.getUI().showModalDialog(form, "Fetched HTML");
Upon launch, the dialog should return Google's homepage.

Google app script - callback confusion

I'm confused about the behavior of the following code sample.
Why can't I access statusLabelU in the callback via the app object ?
It is available in the argument
BTW, what is the type of the argument variable e in the callback ?
function doGet() {
var app = UiApp.createApplication();
var button = app.createButton('Enter Symbol');
app.add(button);
var symbolText = app.createTextBox().setName('symbolText').setId('symbolText');
app.add(symbolText);
var labelU = app.createLabel('Unknown symbol U')
.setId('statusLabelU');
var labelK = app.createLabel('Unknown symbol K')
.setId('statusLabelK');
app.add(labelU);
app.add(labelK);
var handler = app.createServerHandler('myClickHandler');
handler.addCallbackElement(symbolText);
button.addClickHandler(handler);
return app;
}
function myClickHandler(e) {
var app = UiApp.getActiveApplication();
var symU = app.getElementById('symbolText');
var symK = e.parameter.symbolText;
var financeU = FinanceApp.getStockInfo(symU);
var financeK = FinanceApp.getStockInfo(symK);
var label = app.getElementById('statusLabelU');
label.setText(financeU.name);
var label = app.getElementById('statusLabelK');
label.setText(financeK.name);
app.close();
return app;
}
If you run
labelU.setName('labelU');
handler.addCallbackElement(labelU);
you will be be able to access the value of the label in the callback like so:
var value = e.parameter.labelU;
The argument 'e' (or 'eventInfo') contains information about how the callback was triggered. There is some general information about user ID, x/y position of cursor, and also the source element that triggered the callback. Apart from that, values from widgets that are explicitly added to the handler will be accessible as parameters. You can always check out the content by doing a
Logger.log(e);
and check out the log from the coding environment (cmd/ctrl + return).
Actually you can access statusLabelU in the callback via the app object. What you cannot do (at least I dont know any way) to access the contents of a TextBox except than passing it as a parameter to your event-handler via addCallbackElement (you can also pass a container to addCallbackElement, then all elements in this container are passed to your event-handler). So what happens in your example:
var symU = app.getElementById('symbolText');
returns a kind of Proxy of your TextBox, which returns, when converted to a string 'Generic'.
FinanceApp.getStockInfo('Generic');
then in turn returns undefined, which is then set as Text of your label statusLabelU.
Yeah it took me a while to understand what was going on. The way I finally understood it is this:
The server processes stuff, then serves up UI to the client. Every time the client does something, like click a button, he submits this stuff to the server, but the server has no recollection of what it did before, so all those variables you made prior to serving the UI to the client, it no longer knows.
Thus if you want the server to remember those values it created from before serving the client, then you need to embed them along with the UI sent to the client so that when he does something, the data gets sent back to the server.
That embedded crap is considered a hidden callback element, something the user doesn't interact with, and is solely there to pass it back to the server during the next processing action. The 'normal' callback elements are data the server doesn't know yet, such as form elements (names, addresses, etc). It will need to know this information once the user hits the submit button to process it, so that's why it's called callback info.

Verifying file download with Selenium

I need to use selenium to verify a download. I need to click on the download file link and check that it is downloadable or not. (Means download is starting or not)
I need to create a simple HTML script for this. But as Selenium does not recognize the 'Save As' dialog box for file download, I am not able to proceed.
Is there any solution within Selenium for this. I cannot use any other 3rd party tool as this is a part of centralized UI testing script.
Thanks in advance.
My solution (in C#) is get the Url of the file to download and any cookie and make the request using WebClient:
var testLink = seleniumDriver.FindElement(By.LinkText("Link to file"));
var pdfHref = testLink.GetAttribute("href");
var manage = seleniumDriver.Manage();
var cookies = manage.Cookies.AllCookies;
using (var wc = new WebClient())
{
foreach (var cookie in cookies)
{
var cookieText = cookie.Name + "=" + cookie.Value;
wc.Headers.Add(HttpRequestHeader.Cookie, cookieText);
}
var fileResult = wc.DownloadData(new Uri(pdfHref));
// or use wc.DownloadString or wc.DownloadFile
// Do any test required
}

How do I send an HTML Form in an Email .. not just MAILTO

I have an HTML form for people to fill out, and I want it so when they click the submit button, it will just send the email, not bring up their email and ask them to send the message themselves.
When I use:
<form action="MAILTO:emailaddress#email.com"... >
All that does is open up a new window and populates the body of the email, but I want it to just send an email.
And is there a way to format the output of what the email will look like? Instead of just a list of the field names and the entered value.
Thanks.
> 2021 Answer = Easy Way using GMail (5 Mins)
We had a similar challenge to solve yesterday, and we solved it using a Google Apps Script!
Send Email From an HTML Form Without a Backend (Server) via Google!
The solution takes 5 mins to implement and I've documented with step-by-step instructions: https://github.com/nelsonic/html-form-send-email-via-google-script-without-server
Brief Overview
A. Using the sample script, deploy a Google App Script
Deploy the sample script as a Google Spreadsheet APP Script:
google-script-just-email.js
remember to set the TO_ADDRESS in the script to where ever you want the emails to be sent.
and copy the APP URL so you can use it in the next step when you publish the script.
B. Create your HTML Form and Set the action to the App URL
Using the sample html file:
index.html
create a basic form.
remember to paste your APP URL into the form action in the HTML form.
C. Test the HTML Form in your Browser
Open the HTML Form in your Browser, Input some data & submit it!
Submit the form. You should see a confirmation that it was sent:
Open the inbox for the email address you set (above)
Done.
Everything about this is customisable, you can easily
style/theme the form with your favourite CSS Library
and Store the submitted data in a Google Spreadsheet
for quick analysis.
The complete instructions are available on GitHub:
https://github.com/nelsonic/html-form-send-email-via-google-script-without-server
You are making sense, but you seem to misunderstand the concept of sending emails.
HTML is parsed on the client side, while the e-mail needs to be sent from the server. You cannot do it in pure HTML. I would suggest writing a PHP script that will deal with the email sending for you.
Basically, instead of the MAILTO, your form's action will need to point to that PHP script. In the script, retrieve the values passed by the form (in PHP, they are available through the $_POST superglobal) and use the email sending function (mail()).
Of course, this can be done in other server-side languages as well. I'm giving a PHP solution because PHP is the language I work with.
A simple example code:
form.html:
<form method="post" action="email.php">
<input type="text" name="subject" /><br />
<textarea name="message"></textarea>
</form>
email.php:
<?php
mail('youremail#example.com', $_POST['subject'], $_POST['message']);
?>
<p>Your email has been sent.</p>
Of course, the script should contain some safety measures, such as checking whether the $_POST valies are at all available, as well as additional email headers (sender's email, for instance), perhaps a way to deal with character encoding - but that's too complex for a quick example ;).
I actually use ASP C# to send my emails now, with something that looks like :
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form.Count > 0)
{
string formEmail = "";
string fromEmail = "from#email.com";
string defaultEmail = "default#email.com";
string sendTo1 = "";
int x = 0;
for (int i = 0; i < Request.Form.Keys.Count; i++)
{
formEmail += "<strong>" + Request.Form.Keys[i] + "</strong>";
formEmail += ": " + Request.Form[i] + "<br/>";
if (Request.Form.Keys[i] == "Email")
{
if (Request.Form[i].ToString() != string.Empty)
{
fromEmail = Request.Form[i].ToString();
}
formEmail += "<br/>";
}
}
System.Net.Mail.MailMessage myMsg = new System.Net.Mail.MailMessage();
SmtpClient smtpClient = new SmtpClient();
try
{
myMsg.To.Add(new System.Net.Mail.MailAddress(defaultEmail));
myMsg.IsBodyHtml = true;
myMsg.Body = formEmail;
myMsg.From = new System.Net.Mail.MailAddress(fromEmail);
myMsg.Subject = "Sent using Gmail Smtp";
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 587;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential("testing#gmail.com", "pward");
smtpClient.Send(defaultEmail, sendTo1, "Sent using gmail smpt", formEmail);
}
catch (Exception ee)
{
debug.Text += ee.Message;
}
}
}
This is an example using gmail as the smtp mail sender. Some of what is in here isn't needed, but it is how I use it, as I am sure there are more effective ways in the same fashion.