PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Petrus Vorster on January 04, 2013, 01:47:13 PM

Title: Form capture to E-mail
Post by: Petrus Vorster on January 04, 2013, 01:47:13 PM
Hi
I hope someone can help on this one!
I sometimes need to send a client his billing info straight from my application form.
But instead if sending just the data over and open Outlook, i was thinking of doing a screen capture of the active form and paste that inside a new e-mail in outlook.
My form looks very professional and it would look miles better to put it inside the outlook message (not attach) with just one click and there it goes.

Any suggestions?
Title: Re: Form capture to E-mail
Post by: Robert Eaton on January 09, 2013, 11:15:46 AM
I probably know about enough about this topic to be considered misinformed......

But since there have been no replies I'll put in my 2c.

I would start by looking tin the PB forum in the "Programming Microsoft Office" thread.

http://www.powerbasic.com/support/pbforums/forumdisplay.php?f=43 (http://www.powerbasic.com/support/pbforums/forumdisplay.php?f=43)

A potential problem is the rather tight security that Outlook has. It may wind up asking the user for permission for your program to access Outlook. A potential workaround is a third party program called "Outlook Redemption" that allows you to get around the MS security issues in Outlook. (The big giant company I work for uses it.) There are examples in VB that could be translated over to PB. They have an active Yahoo user group.

http://www.dimastr.com/redemption/home.htm (http://www.dimastr.com/redemption/home.htm)




Title: Re: Form capture to E-mail
Post by: Jim Dunn on January 09, 2013, 11:24:01 AM
Actually, if this is just for YOU to send messages from your local Outlook, you could install http://www.mapilab.com/outlook/security/ on your machine, so the Outlook warnings don't appear.

If you needed clients to send emails, then installing this on all their machines becomes a mess.

The good news is that it's free.  MapiLab is great!
Title: Re: Form capture to E-mail
Post by: Petrus Vorster on January 09, 2013, 01:05:57 PM
Thanks everyone, the Outlook security is indeed an issue.
Nope, it will be the long way then! Our system security in Government is like Fort Knox!
No way they will allow anything else to be installed!
That's why the PB apps can run without being installed!!!!

But thanks a million for the advice!
Title: Re: Form capture to E-mail
Post by: Jim Dunn on January 10, 2013, 01:13:21 PM
Ah, then, you could use Jose's "VB Script" interface, and call a VB Script that would email... see sample VB Script below:

' NOTE:  You must run the following command to allow output from this script to be "command-line aware"
'
' wscript //h:cscript //i //nologo //s
'
' this script will send an email to all those who need certification
' it prints a status every 300 row processed

DebugMode = 1 ' 1 for debug, 0 for production

Set objExcel = Wscript.CreateObject("Excel.Application")
objExcel.Visible = False
Set objWorkbook = objExcel.Workbooks.Open("D:\Docs\zzz.xls")
Set objSheet = objExcel.ActiveWorkbook.Worksheets(3)

wscript.stdout.write "Scanning rows, please wait..." & vbCRLF
x = 2
do while objExcel.Cells(x, 1).Value <> ""
if x mod 300 = 0 then
wscript.stdout.write x & " rows scanned so far..." & vbCRLF
end if
strLastName        = objSheet.Cells(x, 1).Value
strFirstName       = objSheet.Cells(x, 2).Value
strLocation        = objSheet.Cells(x, 4).Value
strStudentName     = strLastName & ", " & strFirstName
strStudentEmail    = objSheet.Cells(x, 5).Value
y = instr(1,strStudentEmail,";",0)
if y then
strStudentEmail1   = trim(left(strStudentEmail,y-1))
strStudentEmail2   = trim(mid(strStudentEmail,y+1))
else
strStudentEmail1   = StrStudentEmail
strStudentEmail2   = ""
end if
' strTeam            = objSheet.Cells(x, 6).Value
' strManagerName     = objSheet.Cells(x, 7).Value
strManagerEmail    = objSheet.Cells(x, 8).Value
y = instr(1,strManagerEmail,";",0)
if y then
strManagerEmail1   = trim(left(strManagerEmail,y-1))
strManagerEmail2   = trim(mid(strManagerEmail,y+1))
else
strManagerEmail1   = StrManagerEmail
strManagerEmail2   = ""
end if

strTemp = ""
strTemp = strTemp & "<font color='ff0000'><u>[automated email regarding your requirements/deadlines]</u></font><br><br>"
strTemp = strTemp & strFirstName & ",<br><br>"
strTemp = strTemp & "The following information is what we have on-file in the database regarding your requirements/deadlines.<br><br>"
strTemp = strTemp & "If any of this information is outdated/incorrect, please contact your manager and POC to update (list attached).<br>"
strTemp = strTemp & "<br><font face=""Courier New"" color=""0000ff"" size=2><b>"
strTemp = strTemp & "NAME--------------: " & strStudentName  & "<br>"
strTemp = strTemp & "LOCATION----------: " & strLocation     & "<br>"
strTemp = strTemp & "EMAIL-------------: " & strStudentEmail & "<br>"
strTemp = strTemp & "MANAGER-----------: " & strManagerEmail & "</b></font><br><br>"
strTemp = strTemp & "If any of this information is outdated/incorrect, please contact your manager and POC to update (list attached).<br><br>"
strTemp = strTemp & "Thx!!<br><br>"
strTemp = strTemp & "<span style='font-size:9.0pt;font-family:""Verdana"",""sans-serif""'><b>Your Name</b></span><span style='font-size:8.0pt;font-family:""Verdana"",""sans-serif""'>, Your Title<br>"
strTemp = strTemp & "Department<br><br><b>Phone</b>: +1 222 333-4444, <b>Mobile</b>: +1 222 333-4444, <b>Fax</b>: +1 222 333-4444<br>"
strTemp = strTemp & "<b>Email</b>: <a href=""mailto:email@domain.com"">email@domain.com</a><br><br></span>"

Set MyOutlookApp = CreateObject("Outlook.Application")
Set MyNamespace = MyOutlookApp.getNamespace("MAPI")

' =======================================================================
myFlag = 1
' ------------------------ Check GAL for student ------------------------
if len(strStudentEmail1) then
Set myRecipient = MyNamespace.CreateRecipient(strStudentEmail1)
myRecipient.Resolve
If Not myRecipient.Resolved Then
wscript.stdout.write "Unknown Student Email 1: " & strStudentEmail1 & vbCRLF
myFlag = 0
End If
Set myRecipient = Nothing
end if
' ------------------------ --------------------- ------------------------
if len(strStudentEmail2) then
Set myRecipient = MyNamespace.CreateRecipient(strStudentEmail2)
myRecipient.Resolve
If Not myRecipient.Resolved Then
wscript.stdout.write "Unknown Student Email 2: " & strStudentEmail2 & vbCRLF
myFlag = 0
End If
Set myRecipient = Nothing
end if
' ------------------------ Check GAL for manager ------------------------
if len(strManagerEmail1) then
Set myRecipient = MyNamespace.CreateRecipient(strManagerEmail1)
myRecipient.Resolve
If Not myRecipient.Resolved Then
wscript.stdout.write "Unknown Manager Email 1: " & strManagerEmail1 & vbCRLF
myFlag = 0
End If
Set myRecipient = Nothing
end if
' ------------------------ --------------------- ------------------------
if len(strManagerEmail2) then
Set myRecipient = MyNamespace.CreateRecipient(strManagerEmail2)
myRecipient.Resolve
If Not myRecipient.Resolved Then
wscript.stdout.write "Unknown Manager Email 2: " & strManagerEmail2 & vbCRLF
myFlag = 0
End If
Set myRecipient = Nothing
end if
' =======================================================================

If myFlag = 1 and strLocation <> "" then
Set MyItem = MyOutlookApp.CreateItem(0) ' 0 = olMailItem
With MyItem
'.Recipents.Add(strStudentEmail)
.To = strStudentEmail
.Cc = strManagerEmail
.Subject = "Reminder: Requirements/Deadlines"
.ReadReceiptRequested = False
.HTMLBody = strTemp
strAttachment = "D:\file.png"
.Attachments.Add(strAttachment).Displayname = "(file.png)"
strAttachment = "D:\file.xls"
.Attachments.Add(strAttachment).Displayname = "(file.xls)"
End With
if DebugMode then
MyItem.Display
else
MyItem.Send
end if
set MyItem = Nothing
End If

If myFlag = 0 then
wscript.stdout.write "DID NOT SEND TO: " & strStudentEmail & vbCRLF
End If

Set MyNamespace = Nothing
Set MyOutlookApp = Nothing

if DebugMode then
x = 9999 ' will cause script to exit
end if

x = x + 1
loop
wscript.stdout.write x & " rows scanned." & vbCRLF

objExcel.ActiveWorkbook.Saved = True ' to stop Excel from prompting to save
objWorkbook.Close
objExcel.Quit

set objWorkbook = Nothing
set objExcel = Nothing
Title: Re: Form capture to E-mail
Post by: Petrus Vorster on January 10, 2013, 02:14:49 PM
Wow, thanks Jim!
This may just do the trick!
Title: Re: Form capture to E-mail
Post by: Haakon Birkeland on January 11, 2013, 12:28:03 PM
Do Outlook have to be involved at all?!
Title: Re: Form capture to E-mail
Post by: Petrus Vorster on January 11, 2013, 04:03:05 PM
I am afraid so.
The form contains the clients payment details and sometimes one just need to forward this info somewhere else.
Since the form looks kind of nice, I thought of adding the form containing the data as an image inside the mail and not as an attachment.
Since the entire State department uses the MS Office package, outlook is mandatory, nothing else allowed.
I am trying workarounds since IT policies and security is immensely tight.
Its like writing software for the VOGONS (hitchikers guide to the galaxy). Zillions of tonnes op admin, approval, rejections, burocracy. You get the idea! :)
Title: Re: Form capture to E-mail
Post by: Haakon Birkeland on January 11, 2013, 04:50:34 PM
I was thinking you could send it directly from the application.
The SMTP port should be open and I assume you know or can get a/the servername, username and password ...
Title: Re: Form capture to E-mail
Post by: Petrus Vorster on January 23, 2013, 12:18:17 PM
HI
That may be an option!!!
From my workstation/s yes, but it would be used by other people too.
For now that seem workable. You have some examples on this?
I have never written anything that would email directly.

Thanks for the suggestion!!!

Title: Re: Form capture to E-mail
Post by: Haakon Birkeland on January 23, 2013, 01:42:59 PM
My very first application was about gathering some information from customers of a company and then have it sent back through mail. That's how I got to find and know PowerBasic as visual Basic needed to much drag and bandwidth was at limit back then. â€" Yes it's that long ago.

That is so many years ago that I have absolutely no clue where that code has taken it's way, but I (think I) recall it was code from the PowerBasic download repository. Less distant than that I'v used some FTP library by Don Dickinson for sending data from a Excel spreadsheet. I'm not sure, but he might have made something for POP/SMTP too.

{checking PB}

I assume the forums, perhaps these forums too, have something useful for sending e-mails as well but here ( http://www.powerbasic.com/support/downloads/internet.htm ) is the page where there is some stuff from PowerBasic, Don and others.
Title: Re: Form capture to E-mail
Post by: Paul Squires on January 23, 2013, 05:54:57 PM
Check out my send email class (and subsequent enhancements by others):
http://www.powerbasic.com/support/pbforums/showthread.php?t=41961
Title: Re: Form capture to E-mail
Post by: José Roca on January 23, 2013, 06:51:08 PM
I integrated Paul's class in my headers (CAfxStmpMail.inc) with minimal changes, such as changing the logic of the return value of the SendMail method, and documented it in the help file (WinApiHeaders.chm).
Title: Re: Form capture to E-mail
Post by: Petrus Vorster on January 24, 2013, 04:35:07 PM
Thanks everyone, its going to be a long weekend trying this!!!!
Title: Re: Form capture to E-mail
Post by: Haakon Birkeland on January 24, 2013, 07:30:05 PM
QuoteI integrated Paul's class in my headers (CAfxStmpMail.inc)

Took that as a hint to re-download the header files and documentation. ( http://www.jose.it-berater.org/smfforum/index.php?topic=4558.15 ). 8o)