Page 1 of 2

Email using API [shell32.dll]

Posted: Fri Apr 13, 2012 12:40 pm
by Darren
Can anybody help???

I have this short visual basic code that I am trying to convert to FnxBasic


Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Const SW_SHOW = 5

Private Sub cmdSend_Click()
    ShellExecute hwnd, _
        "open", _
        "mailto:" & txtTo.Text & _
        "?cc=" & txtCc.Text & _
        "&bcc=" & txtBcc.Text & _
        "&subject=" & txtSubject.Text & _
        "&body=" & Replace(txtMessage.Text, vbCrLf, "%0D%0A"), _
        vbNullString, vbNullString, _
        SW_SHOW
End Sub

Here is my program...

    LoadLibrary "C:WINDOWSsystem32shell32.dll"

    Declare Email As "ShellExecuteA" Of "shell32.dll" 
        hwnd As Long
        lpOperation As String
        lpFile As String
        lpParameters As String
        lpDirectory As String
        nShowCmd As Long
    End declare

    With Email
        `hwnd, "open", "mailto:" & "joe-bloggs@aaa.net" & "subject=" & "DARRENS TEST" & "&body=" & Replace("DARREN SMITH WAS HERE", vbCrLf, "%0D%0A"), vbNullString, vbNullString,5
        Execute
    End With

Can anybody tell me what I am doing wrong?

Many thanks in advance!!

Darren

Email using API [shell32.dll]

Posted: Fri Apr 13, 2012 3:42 pm
by Marco
hi, you must set the variables of the api call.

email.hnwd=form.hwnd
email.lpoperation="open"
etc
then execute your api with the statement:
email.execute

i hope this will help,best regards

Email using API [shell32.dll]

Posted: Sat Apr 14, 2012 9:23 am
by Darren
After spending hours on the the program, I cannot figure out how to fully implement the changes that you have told me about, could you please expand on your reply?

Kindest Regards

Darren

Email using API [shell32.dll]

Posted: Sat Apr 14, 2012 3:42 pm
by Marco
hi, here is an example,
This must help i hope, otherwise ask again.
best regards




Declare Email As "ShellExecuteA" Of "shell32.dll"
? hwnd As Long
? lpOperation As String
? lpFile As String
? lpParameters As String
? lpDirectory As String
? nShowCmd As Long
End declare

sub openmailbox(address as string,subject as string,body as string)
? email.lpoperation="open"
? email.lpfile="mailto:"+address+"?subject="+subject+"&body="+body
? email.execute
end sub

openmailbox("joe-bloggs@aaa.net","DARRENS TEST","What will you ask?")


Email using API [shell32.dll]

Posted: Sat Apr 14, 2012 5:36 pm
by Marco
Ther is a bug in the open command so you must put it first in a variable, i`ll try to fix it.
but you could also do this:

sub openmail(address as string,subject as string,body as string
  dim operation as string
  operation= "mailto:"+address+"?subject="+subject+"&body="+body
  open operation
end sub

openmail("joe-bloggs@aaa.net","DARRENS TEST","What will you ask?")

best regards

Email using API [shell32.dll]

Posted: Sun Apr 15, 2012 10:21 am
by Darren
This is my program, so far!

Declare Email As "ShellExecuteA" Of "shell32.dll"
    hwnd As Long
    lpOperation As String
    lpFile As String
    lpParameters As String
    lpDirectory As String
    nShowCmd As Long
End declare

Sub OpenMailBox(Address As String, Subject As String, Body As String)
    Email.lpoperation = "open"
    Email.lpfile = "mailto:" + Address + "?subject=" + Subject + "&body=" + Body
    Email.Execute
End Sub

OpenMailBox("d.j.smith@aim.com","DARRENS TEST","What will you ask?")

Can you get it to work?

It does not seem to work, any ideas?

Kindest Regards

Darren

Email using API [shell32.dll]

Posted: Sun Apr 15, 2012 3:38 pm
by Marco
I don`t get i`ve copied the code from your message. Downloaded fnx 12-2011. And run it. It works perfect. I use outlook express and windows xp.
the programs pops up with the text filled in. Anyone any suggestion?

Email using API [shell32.dll]

Posted: Mon Apr 16, 2012 7:59 am
by Darren
Sorry, my mistake. Must of been a senior moment!!!!

Just two more quick questions?

Firstly, is it possible to add attachments?

And

How to I automatically, using FNX basic, send the email (eg press the send key)?

Many thanks!!!

Darren

Email using API [shell32.dll]

Posted: Mon Apr 16, 2012 8:21 pm
by Marco
I am afraid that is not possible because i found this on the internet:

the most simple one is to use the ShellExecute API call to send an email using the default e-mail client software installed on a user`s machine, this approach is ok, but you are unable to send attachments in this way.

I think you must find a executable or dll to send complete emails with an attachment and execute it with fnxbasic. You can use sendkeys to manipulate the email program but this will only aim a specified email program. If I find something usefull i will notify you.

maybe you can do something with:
http://caspian.dotconf.net/menu/Software/SendEmail/

best regards

Email using API [shell32.dll]

Posted: Wed Apr 18, 2012 9:09 am
by Darren
Hi,

I am using Microsoft Outlook as my default email.

The only real problem that I have is automatically sending the email by somehow pressing the "send" key on outlook (using sendkeys).

I have tried using this approach but failed, any suggestions?

Here is my updated code that takes care of Cr (Carrage Returns)

Declare Email As "ShellExecuteA" Of "shell32.dll"
    hwnd As Long
    lpOperation As String
    lpFile As String
    lpParameters As String
    lpDirectory As String
    nShowCmd As Long
End declare

Dim EmailAddress As String

Dim Subject As String

Dim OutputString As string

EmailAddress = "d.j.smith@aim.com"

Subject = "Darrens Test"

OutputString = "Hello Darren," + Cr

OutputString = OutputString + "How are you?" + Cr

OutputString = OutputString + "" + Cr

OutputString = OutputString + "Hope that you are fine!" + Cr

OpenMailBox(EmailAddress, Subject, OutputString)

Sub OpenMailBox(Address As String, Subject As String, Body As String)
    Email.lpoperation = "open"
    Email.lpfile = "mailto:" + Address + "?subject=" + Subject + "&body=" + ReplaceSubStr$(OutputString, Chr$(13), "%0D%0A")
    Email.Execute
End Sub

Many thanks in advance !!!!

Kindest Regards

Darren