PDA

View Full Version : Email Input Text ??



octane6228
02-17-2004, 03:29 PM
Hello....I'm trying to have an email open and fill in the blanks...My question is how to I get a variable outputted in the body of the message ???

Here's what I'm playing with...

result = firstname;

File.OpenEmail("user1@yourdomain.com?CC=user2@yourdomain.com&BCC=user3@yourdomain.com&Subject=Your subject here&Body=%result%", SW_SHOWNORMAL);


Any ideas would be helpful...

Thanks

CWRIGHT
02-17-2004, 04:27 PM
This should work:

result = firstname;

File.OpenEmail("user1@yourdomain.com?CC=user2@yourdomain.com&BCC=user3@yourdomain.com&Subject=Your subject here&Body=" .. result, SW_SHOWNORMAL);

Bruce
02-17-2004, 04:30 PM
This is a great site to use also.

Great site (http://developer.netscape.com/viewsource/husted_mailto/mailto.html)

octane6228
02-17-2004, 05:14 PM
Thanks CWRIGHT.....Any idea on how I can do multiple items instead of just one variable ? The entries are comming from a form I created with mutiple user entries...I want all these entries sent to the body of the email.

Thanks for any help

TJ_Tigger
02-17-2004, 07:43 PM
To save space you might want to build the body as a variable and then put that into your File.OpenEmail action. For instance:



input1 = "Fname Lname"
input2 = "123 anystreet"
input3 = "AnyTown"
input4 = "IA"
input5 = "52402"
input6 = "I am writing you to tell you about the wonderful resource you have provided to me in this AMS5 product"

result = input6 .. "\r\n" .. input1 .. "\r\n".. input2 .. "\r\n".. input3 .. ", " .. input4 .. " " .. input5

File.OpenEmail("user1@yourdomain.com?CC=user2@yourdomain.com&BCC=user3@yourdomain.com&Subject=Your subject here&Body=" .. result, SW_SHOWNORMAL);


I hope that helps

CWRIGHT
02-18-2004, 03:05 AM
Yep, I'd do it as TJ_Tigger has shown, perhaps even use variables for the email addresses as well. The AMS help has some good examples on concatenating strings.

Please note that you will need to use %0D%0A rather than \r\n for a return/new line as it is a URL being used with the File.OpenEmail action (see Bruce's link).

octane6228
02-19-2004, 12:59 PM
That all works great !!

Here's my next problem.....I have two pages to be filled out before the email is sent.....After page 1 is filled out the user hits the "next" button to continue on to page 2....The problem is that the inputted user data from page 1 is lost and only page 2 data is posted to the email ???

Any ideas why the inputted info is lost from page one to page two ?

--"Page 1 - Next page buton - ON CLICK"
input1 = Input.GetText("alternatename");
input2 = Input.GetText("alternateaddress");
input3 = Input.GetText("motherhealthcard");
input4 = Input.GetText("motherbirthdate");
input5 = Input.GetText("alternatetelephone");
input6 = Input.GetText("alternatefax");
input7 = Input.GetText("alternaterelationship");
input8 = Input.GetText("alternateapt");
input9 = Input.GetText("fatherhealthcard");
input10 = Input.GetText("fatherbirthdate");
input11 = Input.GetText("fatherworktelephone");
input12 = Input.GetText("fatherworkfax");
input13 = Input.GetText("alternateemail");
input14 = Input.GetText("aptnumber");
input15 = Input.GetText("alternatecity");
input16 = Input.GetText("alternateprovince");
input17 = Input.GetText("alternatepostalcode");
input18 = Input.GetText("hometelephone");
input19 = Input.GetText("fax");
input20 = Input.GetText("email");
input21 = Input.GetText("deliverydate");
input22 = Input.GetText("hospital");
input23 = Input.GetText("hospitalcity");
input24 = Input.GetText("doctor");
input25 = Input.GetText("doctortelephone");
input26 = Input.GetText("doctorfax");
input27 = Input.GetText("doctoraddress");

Page.Jump("Page2");


--"Page 2 - Send buton - ON CLICK"
input28 = Input.GetText("alternatename");
input29 = Input.GetText("alternaterelationship");
input30 = Input.GetText("alternateaddress");
input31 = Input.GetText("alternateapt");
input32 = Input.GetText("alternatecity");
input33 = Input.GetText("alternateprovince");

input34 = Input.GetText("alternatepostalcode");
input35 = Input.GetText("alternatetelephone");
input36 = Input.GetText("alternatefax");
input37 = Input.GetText("alternateemail");
input38 = Input.GetText("alternatecomment");


--Mothers info printed to email
result = "Mother's First Name:" .. "%0D%0A" .. input1 .. "%0D%0A%0D%0A" .. "Mother's Last Name:" .. "%0D%0A" .. input2 .. "%0D%0A%0D%0A" .. "Mother's Health Card #:"
.. "%0D%0A" .. input3 .. "%0D%0A%0D%0A" .. "Mother's Bith Date:" .. "%0D%0A" .. input4 .. "%0D%0A%0D%0A" .. "Mother's Work Telphone #: " .. "%0D%0A" .. input5
.. "%0D%0A%0D%0A" .. "Mother's Work Fax #:" .. "%0D%0A" .. input6
--fathers info printed to email
.. "%0D%0A%0D%0A" .. "----------------------------------------------------" .. "%0D%0A%0D%0A"
.. "Father's First Name:" .. "%0D%0A" .. input7 .. "%0D%0A%0D%0A" .. "Father's Last Name:" .. "%0D%0A" .. input8 .. "%0D%0A%0D%0A" .. "Father's Health Card #:"
.. "%0D%0A" .. input9 .. "%0D%0A%0D%0A" .. "Father's Bith Date:" .. "%0D%0A" .. input10 .. "%0D%0A%0D%0A" .. "Father's Work Telphone #: " .. "%0D%0A" .. input11
.. "%0D%0A%0D%0A" .. "Father's Work Fax #:" .. "%0D%0A" .. input12
--General info printed to email
.. "%0D%0A%0D%0A" .. "----------------------------------------------------" .. "%0D%0A%0D%0A"
.. "Home Address:" .. "%0D%0A" .. input13 .. "%0D%0A%0D%0A" .. "Apt #:" .. "%0D%0A" .. input14 .. "%0D%0A%0D%0A" .. "City:" .. "%0D%0A"
.. input15 .. "%0D%0A%0D%0A" .. "Province:" .. "%0D%0A" .. input16 .. "%0D%0A%0D%0A" .. "Postal Code: " .. "%0D%0A" .. input17 .. "%0D%0A%0D%0A"
.. "Home Telephone #:" .. "%0D%0A" .. input18 .. "%0D%0A%0D%0A" .. "Home Fax #:" .. "%0D%0A" .. input19 .. "%0D%0A%0D%0A" .. "Email:" .. "%0D%0A" .. input20
--Medical info printed to email
.. "%0D%0A%0D%0A" .. "----------------------------------------------------" .. "%0D%0A%0D%0A"
.. "Delivery Date:" .. "%0D%0A" .. input21 .. "%0D%0A%0D%0A" .. "Hospital:" .. "%0D%0A" .. input22 .. "%0D%0A%0D%0A" .. "Hospital City: " .. "%0D%0A"
.. input23 .. "%0D%0A%0D%0A" .. "Doctor:" .. "%0D%0A" .. input24 .. "%0D%0A%0D%0A" .. "Doctor Telephone #:" .. "%0D%0A" .. input25 .. "%0D%0A%0D%0A"
.. "Doctor Fax #:" .. "%0D%0A" .. input26 .. "%0D%0A%0D%0A" .. "Doctor Address:" .. "%0D%0A" .. input27
--Alternate info printed to email
.. "%0D%0A%0D%0A" .. "----------------------------------------------------" .. "%0D%0A%0D%0A"
.. "Alternate Name:" .. "%0D%0A" .. input28 .. "%0D%0A%0D%0A" .. "Alternate Relationship:" .. "%0D%0A" .. input29 .. "%0D%0A%0D%0A" .. "Alternate Address: " .. "%0D%0A"
.. input30 .. "%0D%0A%0D%0A" .. "Alternate Apt#:" .. "%0D%0A" .. input31 .. "%0D%0A%0D%0A" .. "Alternate City:" .. "%0D%0A" .. input32 .. "%0D%0A%0D%0A"
.. "Alternate Province:" .. "%0D%0A" .. input33 .. "%0D%0A%0D%0A" .. "Alternate Postal Code:" .. "%0D%0A" .. input34 .. "%0D%0A%0D%0A"
.. "Alternate Telephone:" .. "%0D%0A" .. input35 .. "%0D%0A%0D%0A" .. "Alternate Fax:" .. "%0D%0A" .. input36 .. "%0D%0A%0D%0A"
.. "Alternate Email:" .. "%0D%0A" .. input37 .. "%0D%0A%0D" .. "Alternate Comment:" .. "%0D%0A" .. input38

File.OpenEmail("rmharris@rogers.com&Subject=Registration Submission&Body=" .. result, SW_SHOWNORMAL);

rhosk
02-19-2004, 01:24 PM
One option is to make your ..result a global function.

octane6228
02-19-2004, 01:44 PM
How would I get all those inputs into the Global Functions ?

TJ_Tigger
02-19-2004, 01:56 PM
variables are global so make sure that you are not overwritting the result variable when you jump to Page2. I would suggest changing your "result" variable to something else like "emailbody" since "result" is often the default return variable for most actions.

octane6228
02-19-2004, 02:14 PM
No go....I changed my variable name just to be sure but still the same result....after I jump from page 1 to page 2 I lose all the inputted data from page 1....Page 2 inputs are fine just page 1 is lost ????

Any other ideas why I'm losing Page 1 Inputted data ??

CWRIGHT
02-19-2004, 02:59 PM
No idea why you are losing your variable info - what TJ_Tigger said makes most sense.

However, you could make life easier for yourself by entering the info into a table rather than that very long string. The attached project shows you how this would work.

All labels and inputs need to be consecutively numbered. You can then use a loop to read each item of label text and inputted text into a table.

This table is then written to a string (with the return/newline as a delimeter) and this is then used to create the email body. You can even insert lines into the table to create your section seperators.

Let me know if you have any questions.

CW

octane6228
02-19-2004, 04:53 PM
Thanks CWRIGHT,

I put together code as you can see below but now I'm really stumped ???.....This was working fine till I did a in depth test....I can only fill in about 3/4 of the fields of page 1 and then it won't open an email anymore ????

I filled in all 38 inputs over the two pages and then hit the send button....Nothing happened....I then started deleting field by field untill I got to about 15 fields on page 1 filled in then it would open an Email again ??? anything over that 15 or so and no email....

Any help with this would extremely appreciated....!!!

The code is below...




--Page 1

tEmailBody = {};

for x=1, 27 do -- start and end label and input numbers on page

local sLabel = Label.GetText("Label" .. x);
local sInput = Input.GetText("input" .. x);

tEmailBody[x] = sLabel.."%0D%0A"..sInput;

end

Page.Jump("Page5");




--Page 2

for x=28, 38 do -- start and end label and input numbers on page

local sLabel = Label.GetText("Label" .. x);
local sInput = Input.GetText("input" .. x);

tEmailBody[x] = sLabel.."%0D%0A"..sInput;

end

sDividerA = "----------------Mother's Information----------------%0D%0A"
sDividerB = "%0D%0A----------------Father's Information----------------%0D%0A%0D%0A"
sDividerC = "%0D%0A----------------General Information-----------------%0D%0A%0D%0A"
sDividerD = "%0D%0A----------------Medical Information-----------------%0D%0A%0D%0A"
sDividerE = "%0D%0A-----------Alternate Contact Information------------%0D%0A%0D%0A"
sDividerF = "%0D%0A----------------------Comments----------------------%0D%0A%0D%0A"

Table.Insert(tEmailBody, 1, sDividerA) -- insert a divide line into the table
Table.Insert(tEmailBody, 7, sDividerB) -- insert a divide line into the table
Table.Insert(tEmailBody, 15, sDividerC) -- insert a divide line into the table
Table.Insert(tEmailBody, 24, sDividerD) -- insert a divide line into the table
Table.Insert(tEmailBody, 32, sDividerE) -- insert a divide line into the table
Table.Insert(tEmailBody, 43, sDividerF) -- insert a divide line into the table

sBody = Table.Concat(tEmailBody, "%0D%0A%0D%0A", 1, TABLE_ALL) -- convert the table to a string

File.OpenEmail("emailaddress@company.com&Subject=Registration Submission&Body=" .. sBody, SW_SHOWNORMAL);

CWRIGHT
02-19-2004, 05:28 PM
Not sure, but I think you have probably exceeded the limit for the amount of data that can be passed via the OpenEmail action. Just guessing now, but as essentially we are just creating a very long URL here, there will be some restriction to the length to prevent buffer overflows etc.

Shame though - the table way of doing it was pretty neat.

Options would be to split each section into it's own email, or create a text file from the data, and send this as an attachment instead. I don't think this is easy with the OpenEmail action as you would need to Uuencode the file.

There are freeware external email applications which you could use that have their own SMTP email engine, and work from the command-line. I may be able to provide more info tomorrow when I am back at my work computer.

CW

CWRIGHT
02-20-2004, 04:52 AM
Blat.exe is the public domain SMTP program I was thinking of, and I notice there is also a DLL version. You could call this directly from AMS50 and attach all of your info either to a file attachment or a text file used for the email body.

So, once your table is generated, use the TextFile.WriteFromTable action to generate your text file, and then use DLL.CallFunction to send the email.

The attached project includes the code for calling the DLL and blat.dll itself. It should be easy to follow.

You will need to know the SMTP address of your email server, and ensure the "to" address is valid on that server (otherwise it will probably reject the email for trying to relay). Also be aware that some corporate firewalls may block SMTP port 25 from their users, preventing the sending of email using blat.

Link to blat site: http://www.geocities.com/toby_korn/blat/

Hope this helps,
CW

Brett
02-20-2004, 06:53 AM
The very easiest and most reliable way to accomplish this would be to setup a script on your Web server that sends the email and then just use HTTP.Submit to get the email information to the script. If your Web server supports PHP you could get this going in minutes. If not, you can get Web servers that can handle this type of capability for $5-$10 per month.

octane6228
02-20-2004, 02:02 PM
HI CWRIGHT....I'm getting error code 2 using blat.dll

In blat return codes it says 2 stands for...

The server actively denied our connection.
The mail server doesn't like the sender name.


Now in POP3 email client you have to enter your email address and password to be able to receive and send mail, how does blat.dll deal with the password issue ?? I'm assuming thats why I'm being rejected from the smtp server.

Your help is greatly appreciated.

Below is the code to date....






--Page 1

tEmailBody = {};

for x=1, 27 do -- start and end label and input numbers on page

local sLabel = Label.GetText("Label" .. x);
local sInput = Input.GetText("input" .. x);

--tEmailBody[x] = sLabel.."%0D%0A"..sInput;
tEmailBody[x] = sLabel..sInput;
end


Page.Jump("Page2");




--Page 2

for x=28, 38 do -- start and end label and input numbers on page

local sLabel = Label.GetText("Label" .. x);
local sInput = Input.GetText("input" .. x);

tEmailBody[x] = sLabel .. sInput;

end

sDividerA = "----------------Mother's Information----------------"
sDividerB = "----------------Father's Information----------------"
sDividerC = "----------------General Information-----------------"
sDividerD = "----------------Medical Information-----------------"
sDividerE = "-----------Alternate Contact Information------------"
sDividerF = "----------------------Comments----------------------"
sDividerG = " "

Table.Insert(tEmailBody, 1, sDividerA) -- insert a divide line into the table
Table.Insert(tEmailBody, 2, sDividerG) -- insert a divide line into the table

Table.Insert(tEmailBody, 9, sDividerG) -- insert a divide line into the table
Table.Insert(tEmailBody, 10, sDividerB) -- insert a divide line into the table
Table.Insert(tEmailBody, 11, sDividerG) -- insert a divide line into the table

Table.Insert(tEmailBody, 18, sDividerG) -- insert a divide line into the table
Table.Insert(tEmailBody, 19, sDividerC) -- insert a divide line into the table
Table.Insert(tEmailBody, 20, sDividerG) -- insert a divide line into the table

Table.Insert(tEmailBody, 29, sDividerG) -- insert a divide line into the table
Table.Insert(tEmailBody, 30, sDividerD) -- insert a divide line into the table
Table.Insert(tEmailBody, 31, sDividerG) -- insert a divide line into the table

Table.Insert(tEmailBody, 39, sDividerG) -- insert a divide line into the table
Table.Insert(tEmailBody, 40, sDividerE) -- insert a divide line into the table
Table.Insert(tEmailBody, 41, sDividerG) -- insert a divide line into the table

Table.Insert(tEmailBody, 52, sDividerG) -- insert a divide line into the table
Table.Insert(tEmailBody, 53, sDividerF) -- insert a divide line into the table
Table.Insert(tEmailBody, 54, sDividerG) -- insert a divide line into the table





TextFile.WriteFromTable("C:\\temp\\EmailInfo.txt", tEmailBody, false);


--Mail text file using smtp server blat.dll

sMailServer = "smtp.broadband.rogers.com";
sEmailFrom = "rmharris@rogers.com";
sEmailTo = "rmharris@rogers.com";
sEmailSubject = "Registration Information";
sEmailBody = "AutoPlay\\DOCS\\EmailInf.txt";
sAttachment = "AutoPlay\\DOCS\\EmailInf.txt";

sParameters = "\""..sEmailBody.." -server "..sMailServer.." -f "..sEmailFrom.." -t "..sEmailTo.." -s \""..sEmailSubject.."\" -attach "..sAttachment.."\"";
Dialog.Message("Info", sParameters);
sDLLReturn = DLL.CallFunction("AutoPlay\\DLL\\blat.dll", "Send", sParameters, DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);

if (sDLLReturn == "0") then
Dialog.Message("Info", "Email successfully sent");
else
Dialog.Message("Info", "Error sending email: "..sDLLReturn);
end

CWRIGHT
02-20-2004, 05:52 PM
You can use the following blat commands if your SMTP server requires authentication:

-u <username> : Username for AUTH LOGIN (use with -pw)
-pw <password> : Password for AUTH LOGIN (use with -u)

so:

sMailServer = "smtp.broadband.rogers.com";
sEmailFrom = "rmharris@rogers.com";
sEmailTo = "rmharris@rogers.com";
sEmailSubject = "Registration Information";
sEmailBody = "AutoPlay\\DOCS\\EmailInf.txt";
sAttachment = "AutoPlay\\DOCS\\EmailInf.txt";
sUsername = "myusername";
sPassword = "mypassword";

sParameters = "\""..sEmailBody.." -server "..sMailServer.." -u "..sUsername.." -pw "..sPassword.." -f "..sEmailFrom.." -t "..sEmailTo.." -s \""..sEmailSubject.."\" -attach "..sAttachment.."\"";
Dialog.Message("Info", sParameters);
sDLLReturn = DLL.CallFunction("AutoPlay\\DLL\\blat.dll", "Send", sParameters, DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);


Download the blat.exe zip file from the main blat site - it includes a readme file with all the command line options.

TJ_Tigger
02-20-2004, 10:18 PM
If you have access to a server that handles PHP you can use this as a script on that server and use the HTTP.Submit.

<?php

//setvariables
//$to="myemail@yahoo.com";

// send email
mail ("$to","$subject","$message","From: amscd@yahoo.com"
);

// end script
exit;

?>

octane6228
02-21-2004, 02:22 AM
Hi CWRIGHT......I'm closer now, but I'm getting an error code 1 now and can't figure out why ???

I know my SMTP server, username and password are correct, but also not sure exactly what error 1 code it is....

"Error Code 1"

Unable to open SMTP socket
SMTP get line did not return 220
command unable to write to socket
Server does not like To: address
Mail server error accepting message data.


Maybe you have some more ideas ???


Thanks in advance....





--Mail text file using smtp server blat.dll

sMailServer = "smtp1.sympatico.ca";
sEmailFrom = "rmharris@on.aibn.com";
sEmailTo = "robin.harrison@securevision.ca";
sEmailSubject = "Registration Information";
sEmailBody = "C:\\temp\\EmailInfo.txt";
sAttachment = "C:\\temp\\EmailInfo.txt";
sUsername = "rmharris@on.aibn.com";
sPassword = "??????????";


sParameters = "\""..sEmailBody.." -server "..sMailServer.." -u "..sUsername.." -pw "..sPassword.." -f "..sEmailFrom.." -t "..sEmailTo.." -s \""..sEmailSubject.."\" -attacht "..sAttachment.."\"";

Dialog.Message("Info", sParameters);
sDLLReturn = DLL.CallFunction("AutoPlay\\DLL\\blat.dll", "Send", sParameters, DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);

if (sDLLReturn == "0") then
Dialog.Message("Info", "Email successfully sent");
else
Dialog.Message("Info", "Error sending email: "..sDLLReturn);
end

Worm
02-21-2004, 05:59 AM
Make sure your mail server supports SMTP authentication or it'll never work. Or at least it shouldn't work if the mail server is set up properly to deny relaying.

octane6228
02-21-2004, 09:27 AM
Not sure exactly what you mean Worm ??? Will this work with a main stream ISP such as rogers , comcast, sympatico, etc...??? Isn't blat just acting like outlook express in a sense ??? How does outlook work but not blat ???

Any thoughts are appreciated...

Worm
02-21-2004, 09:44 AM
What server would you be sending the email through? Are you going to ask the end-user to provide their SMTP server? Not too likely many will know. If you're going to hardcode your email/SMTP server into the app, then the email more than likely wouldn't be sent.

Most email servers are set to prevent relaying, which is what you'd be doing if you were trying to send an email from your app running on my machine through your ISPs email server. There are mail servers that will let you do SMTP Authentication to allow you to send mail through the server. By authenticating against the server, it knows that you are allowed to send mail through, regardless of where it's coming from.

octane6228
02-21-2004, 10:31 AM
OK Worm.....So whats the difference when I set up outlook express with smtp.server, username, password.....it lets me send emails all day long.....I'm using the same info in the blatt.dll (smtp.server/username/password) so why isn't it going thru ???

Very confused....

Worm
02-21-2004, 10:49 AM
Well, lets go back to your original error.

The blat dll is looking for the server to return a 220 when connecting.

Try this. Click Start/Run type: telnet your.smtp_server.com 25

Click OK

does the server return a 220 in the very first line that shows? If so, does it take a little long?

octane6228
02-21-2004, 04:59 PM
Hi Worm...

Yes it returns the 220 line almost instantly....