/    Sign up×
Community /Pin to ProfileBookmark

Is it possible to specify email body content using javascript?

I’m working on a form that will only be used on a intranet. what I need to know is if it is possible to build a string variable that will contain the message content and send it to a specified email address?

example:
theform = document.user_account_request;
msgcont = “user data”
theform.action = “mailto:” + theform.recipient.value + “;” + theform.employee_email.value + “;” + theform.other_email.value + “?Subject=APPROVE: User Access Request form for ” + theform.employee_name.value + “&body=” + msgcont.value;

TIA,

Chris

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@veslachJul 11.2004 — The short answer to your question is - Yes, using 'body=message content' inside the mailto string *will* populate the email body with 'message content'. The only issue is that the 'message content' starts at the 2nd line rather than the 1st line of the email.

Another issue with sending an email via a form's action="mailto:..." is the fact that the user can modify the email however they want before pressing the send button. This brings up several issues, here's a couple -

  • 1. does the user have an email client available via their browser or not. Since you're on an intranet & can control the users environment, it shouldn't be an issue.


  • 2. this method actually brings up an email (like clicking a mailto link). The user can do anything to the email (from not sending it to deleting/modifying the subject line, message body, To: field, etc). If you want the structure of the email controlled, it would be better to do this via a server-side script.


  • 3. can the user's email server actually send the email to the recipient email addy? i.e. if the user decides to use their external email address (i.e. [email][email protected][/email]) to send the email & the recipient has an internal email address (i.e. mike.jones@mailbox) the email will never get to the recipient.
  • Copy linkTweet thisAlerts:
    @cjgtekauthorJul 11.2004 — I've tried using the code I included in the original message, but it's not working. the actual content contains about 30 lines of data. I added a header line to spoof the problem you mentioned, but the variable doesn't seem to be accepting the form field data.

    sending the email's not a problem. that portion works just fine. I have it set to send emails out to up to three people (two mandatory, one optional). the only issue is that Outlook keeps bringing up a message box that an external app is trying to send email. not sure how to turn that off. maybe a vbscript command?


    Chris
    Copy linkTweet thisAlerts:
    @cjgtekauthorJul 13.2004 — one other question: is it possible to add an external attachment to the mailto: command?

    tia,

    Chris
    Copy linkTweet thisAlerts:
    @veslachJul 13.2004 — I wasn't sure if there was an &attachment= piece that was available for the mailto: string, but after googling for "mailto subject body attachment" I can across this 1 link that refers to some code that lets you do this using outlook as the mail client.

    http://www.notestips.com/80256B3A007F2692/0/4CF1A694C1AAEC4780256D610013FEDE?OpenDocument

    Please note that I wasn't able to get this to work using an "a" link or inside a forms action. Then again I was using WinXP & Outlook Express for this test.

    Another idea is to post a link to the external file instead of including it. One company I work for recently started this as a new process to cut down on bandwidth usage. Then again this depends on your network & server setup. If you're using IMAP for email & your file server is on the same box, may as well attach the file.

    I also found another site that reminded me about the 255 character limit in the URL. IE/Outlook combo may extend this, I'm not sure. Then again, VBScript might allow for some interesting coding as well.


    --------------------------
    pet peeve for worste public internet site - all menu links are input buttons with onclick coded with vbscript.
    Copy linkTweet thisAlerts:
    @cjgtekauthorJul 13.2004 — Here's a code snippet I'm trying to debug. Basically, it replaces the form field data in the form mailto: with a string built from the non-NULL form field values. the mailto works fine until it gets to the &BODY part. I've used a document.write to confirm that the msgCont string is being built. I just can't get the mailto: to accept it and send it. Any ideas?

    TIA,

    Chris



    // JavaScript Document

    function SubmitForm() {

    var msgCont

    msgCont = "******";

    msgCont += "<p>User Access Request form for <b>" + document.forms[0].employee_name.value + "1</b><br>";

    if (document.user_account_request.Status_New_User.checked == true) {

    msgCont += "New User: " + document.forms[0].Status_New_User.value + "<br>";

    }

    if (document.user_account_request.Status_Rehire.checked == true) {

    msgCont += "Rehire: " + document.forms[0].Status_Rehire.value + "<br>";

    }

    if (document.user_account_request.Status_Contractor.checked == true) {

    msgCont += "Contractor: " + document.forms[0].Status_Contractor.value + "<br>";

    }

    if (document.forms[0].Disable.checked == true) {

    msgCont += "*
    **
    Disable User Account***" + "<br>";

    }

    msgCont += "Type of Request: " + document.forms[0].type_of_request.value + "<br>";

    msgCont += "Type of User: " + document.forms[0].type_of_user.value + "<br>";

    if (document.forms[0].type_of_user_other.value.length > 0) {

    msgCont += "Other: " + document.forms[0].type_of_user_other.value + "<br>";

    }

    msgCont += "Employee Type: " + document.forms[0].employee_type.value + "<br>";

    msgCont += "Business Unit: " + document.forms[0].business_unit.value + "<br>";

    if (document.forms[0].business_unit_other.value.length > 0) {

    msgCont += "Other Unit: " + document.forms[0].business_unit_other.value + "<br>";

    }


    theform = document.user_account_request;
    theform.action = "mailto:" + theform.recipient.value + ";" + theform.employee_email.value + ";" + theform.other_email.value + "?Subject=APPROVE: User Access Request form for " + theform.employee_name.value + "&Body=" + msgCont.value;

    }
    Copy linkTweet thisAlerts:
    @veslachJul 13.2004 — unfortunately i'm currently at work & don't have access to my normal tools. Check to see that the entire length of the whole mailto: string is 255 chars or less... i.e.

    [FONT=courier new]mailto:[email protected]?subject=abc&body=def[/FONT]

    [FONT=courier new]1234567890123456789012345678901234567890123456789[/FONT]

    this is actually 49 characters in length. It could be that adding the extra To, CC, & BCC persons increases the total length beyond 255 chars. The best bet if things are going to hit over 255 chars regularly is to set the form to send the information via POST to a server-side script that will send out an email via SMTP.
    Copy linkTweet thisAlerts:
    @cjgtekauthorJul 13.2004 — the body is most definitely going to be over 255 characters. there are over 20 fields and a dozen are required. :mad:

    I'm not versed in Perl, so I can't create a script. well, I guess I'm going to have come up with another way to do this. (the thing that really grates at me is that I could do this no problem in cold fusion. but we don't have a cf server here. ? )

    thanks for your help,

    Chris
    ×

    Success!

    Help @cjgtek spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.1,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...