javascript mailto attachment not showing up - javascript

i'm trying to create a small web app wherein in one form, the user may type in certain parameters as part of the message, then after he hits a button, it will show an Outlook (depends on his default email client) email client popup with all the details he placed.. and then it will include an attachment.
the javascript code looks like this:
function submitReport()
{
var remarks = document.getElementById('remarks').value;
if(remarks != '')
body += 'Remarks: '+remarks;
var href = 'mailto:bug_support#emailadd.com?subject=[Bug Report] '+menu_path+'&body='+body;
href += '&attachment="C:\\debug.log"';
var form = DomUtils.createForm();
form.setAttribute('action', href);
form.submit();
}
i tried alerting the "href" variable and it shows:
mailto:bug_support#emailadd.com?subject=[Bug Report]&body=message_bodyReport Type: MonthlyStart Date: 2010-05-01 00:00:00End Date: 2010-05-31 23:59:59&attachment="C:\debug.log"
and surely an outclient popsup with all the subject, recepient email address, body..
but no attachment. anybody encountered this before? :(
the outlook used here is 2007..
if i run the web app in IE, it actually says an error
"The command line argument is not valid. Verify the switch you are using."
any ideas?

There is no way for a web page to cause a browser to open the user's email client with a file pre-attached from the hard disk.
Use a form and process it server side, or provide simple instructions along the lines of:
<p>Send an email to foo#example.com
and attach your log file.</p>

Related

How to send whatsapp message via Javascript

Hi I would like to know if there is something to send a whatsapp message using javascript or something I was searching but I did not find any new post. This is not for any special purpose. I found this but it only works if you have whatsapp web. I was thinking on clicking on a link to send a default message to a default number
Send Message
Just make use of this function in web browser to get it running as you want.
Note: You need to run the code manually through browser console with an opened conversation in WhatsApp
(web version).
function sendMessage(message){
const mainEl = document.querySelector('#main')
const textareaEl = mainEl.querySelector('div[contenteditable="true"]')
if(!textareaEl) {
throw new Error('There is no opened conversation')
}
textareaEl.focus()
document.execCommand('insertText', false, message)
textareaEl.dispatchEvent(new Event('change', { bubbles: true }))
setTimeout(() => {
(mainEl.querySelector('[data-testid="send"]') || mainEl.querySelector('[data-icon="send"]')).click()
}, 100)
}
Ref: https://github.com/Matt-Fontes/SendScriptWhatsApp/blob/main/shrekSendScript.js
I find this way is a better way to send a msg to WhatsApp unknowing number.
// github: omar-bakhsh
function send_handle(){
let num=document.getElementById("number").value;
let msg= document.getElementById("msg").value;
let name= document.getElementById("name").value;
var win = window.open(`https://wa.me/${num}?text=I%27m%20api%20msg%20hello%20${name}%20friend%20${msg}`, '_blank');
// win.focus();
}
<div>
<h3>whatsapp send app </h3>
<h6>add number without space like 17272912606 not <strike>+1 (727) 2912606 </strike></h6>
<input id="number" type="numric" placeholder="phone 966506666666" >
<input id="name" type="text" placeholder="name" >
<input id="msg" type="text" placeholder="type msg" >
<button onclick="send_handle()">send</button>
You can do this:
Send Message
Whatsapp dosen't support sending messages from the PC. Every message has to come from a Phone. Whatsapp web is just redirecting the messages to your phone wich is then sending the message. If you use their api you only can let users send a message to any number via Whatsapp using their phone. To predetermine the message use:
https://api.whatsapp.com/send?phone=whatsappphonenumber&text=urlencodedtext
more: https://faq.whatsapp.com/en/android/26000030/?category=5245251
On the WhatsApp developers hub, they demonstrated a walkthrough guide on how to opt-in for a developer account on meta, and create an app so can make api calls if you want to use WhatsApp programmatically,
Short version:
Register as a Meta Developer
Enable two-factor authentication for your account
Create a Meta App: Go to developers.facebook.com > My Apps > Create App.
Select the "Business" type and follow the prompts on your screen.
Scroll down to find the "WhatsApp" product and click Set up.
Select an existing Business Manager, if you don't the wizard will guide you to create one.
Next screen will show you a demo.
If you need a listener when your number receive a message or reply, you should register webhooks.
Add your phone number to use it programmatically. and it shouldn't be connected with WhatsApp at all, neither personal or business.
for more details follow the getting started guide:
https://business.whatsapp.com/developers/developer-hub
It's impossible to do it with HTML link. Whatsapp has no official API. But you can find (or write it by yourself) some script to emulate user actions on the site web.whatsapp.com. For example, this one (I did not test it).

Is it possible to send a key code to an application that is not in front?

I'm writing a simple Automator script in Javascript.
I want to send a key-code(or key-storke) to an OS X application that is not in front.
Basically, I want to run this code and do my things while the script opens a certain application, write text, and hit enter - all of this without bothering my other work.
I want something like this:
Application("System Events").processes['someApp'].windows[0].textFields[0].keyCode(76);
In Script Dictionary, there is keyCode method under Processes Suite.
The above code, however, throws an error that follows:
execution error: Error on line 16: Error: Named parameters must be passed as an object. (-2700)
I understand that the following code works fine, but it require the application to be running in front:
// KeyCode 76 => "Enter"
Application("System Events").keyCode(76);
UPDATE: I'm trying to search something on iTunes(Apple Music). Is this possible without bringing iTunes app upfront?
It's possible to write text in application that is not in front with the help of the GUI Scripting (accessibility), but :
You need to know what UI elements are in the window of your specific
application, and to know the attributes and properties of the
specific element.
You need to add your script in the System Preferences --> Security
& Privacy --> Accessibility.
Here's a sample script (tested on macOS Sierra) to write some text at the position of the cursor in the front document of the "TextEdit" application.
Application("System Events").processes['TextEdit'].windows[0].scrollAreas[0].textAreas[0].attributes["AXSelectedText"].value = "some text" + "\r" // r is the return KEY
Update
To send some key code to a background application, you can use the CGEventPostToPid() method of the Carbon framework.
Here's the script to search some text in iTunes (Works on my computer, macOS Sierra and iTunes Version 10.6.2).
ObjC.import('Carbon')
iPid = Application("System Events").processes['iTunes'].unixId()
searchField = Application("System Events").processes['iTunes'].windows[0].textFields[0]
searchField.buttons[0].actions['AXPress'].perform()
delay(0.1) // increase it, if no search
searchField.focused = true
delay(0.3) // increase it, if no search
searchField.value = "world" // the searching text
searchField.actions["AXConfirm"].perform()
delay(0.1) // increase it, if no search
// ** carbon methods to send the enter key to a background application ***
enterDown = $.CGEventCreateKeyboardEvent($(), 76, true);
enterUp = $.CGEventCreateKeyboardEvent($(), 76, false);
$.CGEventPostToPid(iPid, enterDown);
delay(0.1)
$.CGEventPostToPid(iPid, enterUp);

Javascript works in Adobe Reader but not in Nitropdf

I have setup an interactive PDF form with a Javascript button to submit the form by email, extracting data input by the user. The button works fine in Adobe Reader but does nothing in NitroPDF. Is there a problem with the code (see below)?
var cToAddr = this.getField("ComboBox1").value
var cSubLine = "Property Transaction Form " + this.getField("Text1").value
var cBody = "The attached file is the filled-out form. Please open it to review the data."
this.mailDoc({bUI: true, cTo: cToAddr, cSubject: cSubLine, cMsg: cBody})
With the plethora of PDF viewers out there that implement only some of the Acrobat JavaScript API - some more, some less - I recommend testing for the existence of any functions that your document requires before trying to use them. Wrap your code in the snippet below to let the user know that they are using a less capable viewer than what you've programmed the document for.
if (typeof this.mailDoc == 'function') {
// The viewer can mail documents
}
else {
// Warn the user somehow
}

Not a MessageBox related error that is thrown when using a MessageBox server side

The title is most likely confusing for most, so I'll explain it thoroughly.
This is the error I'm getting:
Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
However, it's not being thrown as a result of a MsgBox being used server side.
Another wrench in the mix, this is only occuring on our current production server. The test server, which is set up identically to the production (with the exception of the SSL Cert being different, but that won't matter), is working flawlessly. The dev machine also works without error.
Current code being used in VB codebehind:
Dim DBconn As New OracleConnect 'Custom class file
Try
DBconn.Open(Uname, Pword, SelServ)
If DBconn Is Nothing Then
errorLabel.Text = "Authentication did not succeed. Check user name and password."
Exit Sub
Else
groups = DBconn.GetUserRole()
'Create the ticket, and add the groups.
Dim isCookiePersistent As Boolean = chkPersist.Checked
Dim authTicket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, _
txtUsername.Text, DateTime.Now, DateTime.Now.AddMinutes(60), isCookiePersistent, groups)
'Encrypt the ticket.
Dim encryptedTicket As String = FormsAuthentication.Encrypt(authTicket)
'Create a cookie, and then add the encrypted ticket to the cookie as data.
Dim authCookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
If (isCookiePersistent = True) Then
authCookie.Expires = authTicket.Expiration
End If
'Add the cookie to the outgoing cookies collection.
Response.Cookies.Add(authCookie)
'set session variables
Session("UID") = txtUsername.Text
Session("PWD") = txtPassword.Text
Session("selServ") = StrServer.SelectedValue
SetupTableNames()
'MsgBox(groups, MsgBoxStyle.OkOnly, "HRIS User Role")
Session("gsRole") = groups
'You can redirect now.
'Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUsername.Text, False))
Response.Redirect("~/Account/_Search.aspx")
End If
Catch ex As Exception
errorLabel.Text = "Error authenticating. " & ex.Message
End Try
Code from OracleConnect class:
Public Sub Open(ByVal Uname As String, ByVal Pword As String, ByVal SelServ As String)
OraDb = "Data Source=" + SelServ +
";Persist Security Info=True" +
";User Id=" + Uname +
";Password=" + Pword
conn = New OracleConnection(OraDb)
Try
conn.Open()
Catch ex As OracleException
Select Case ex.Number
Case 1
MesgBox("Error attempting to insert duplicate data.", MsgBoxStyle.OkOnly, "HRIS")
Case 12545
MesgBox("The database is unavailable.", MsgBoxStyle.Critical, "HRIS")
Case Else
MesgBox("Database error: " + ex.Message.ToString(), MsgBoxStyle.Critical, "HRIS")
End Select
Catch ex As Exception
MesgBox(ex.Message.ToString(), MsgBoxStyle.Information, "HRIS")
End Try
End Sub
I'm aware of the MesgBox's in the class file but those are referencing a Sub the uses Javascript that works within the program which has been tested and works as it should.
So my questions are:
Is there something that would trigger this response server side in IIS 7.0 that I haven't found yet?
If it's not viable in IIS, then are there any alternatives that I should look into?
EDIT: The solution to this problem didn't lie within the ASP or VB code but rather with the Oracle set up on the server. For anyone that has a similar problem in the future, I advise looking into the TNS_ADMIN environment/system variables and the TNSNAMES.ORA file and make sure they are correct. If you make any of these changes, make sure to restart the server. My steps involved verifying the TNSNAMES.ORA file was correct, the TNS_ADMIN environment variable was set, then in a cmd prompt using "set tns_admin={filepath}", after all that then restart the server and the site was working perfectly.
The solution to this problem didn't lie within the ASP or VB code but rather with the Oracle set up on the server. For anyone that has a similar problem in the future, I advise looking into the TNS_ADMIN environment/system variables and the TNSNAMES.ORA file and make sure they are correct. If you make any of these changes, make sure to restart the server. My steps involved verifying the TNSNAMES.ORA file was correct, the TNS_ADMIN environment variable was set, then in a cmd prompt using "set tns_admin={filepath}", after all that then restart the server and the site was working perfectly.

CRM 2011 "This page is accessing information that is not under its control"

I have the following javascript on a CRM form which is used to grab a local copy of the Subject entity records:
function refreshSubjects() {
sgc_subjectCache = [];
var options = "$select=Title,SubjectId,ParentSubject";
SDK.REST.retrieveMultipleRecords("Subject", options, refreshSubjectsCallback, function(error) {
alert( error.message );
}, refreshSubjectsComplete);
}
But this results in the annoying "this page is accessing information that is not under its control" dialogue.
I'm not sure why as there is no cross-domain posting going on.
Is there a way to suppress this without compromising browser security?
I found the answer: http://social.microsoft.com/Forums/en-IE/crmdevelopment/thread/6e050347-e584-47c2-aab1-8fdf74e8ef1e
Basically, the domain was correct in the database but I was using "localhost" in my web browser, whereas the SDK was using the FQDN.
Calling the site via the FQDN in the browser removed the problem!

Categories

Resources