Email using API [shell32.dll]

In this category you can exchange your programming questions and solutions.
Darren
Posts: 63
Joined: Wed May 11, 2011 11:55 am

Email using API [shell32.dll]

Post: # 854Post Darren
Fri Apr 13, 2012 12:40 pm

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

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

Email using API [shell32.dll]

Post: # 855Post Marco
Fri Apr 13, 2012 3:42 pm

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

Darren
Posts: 63
Joined: Wed May 11, 2011 11:55 am

Email using API [shell32.dll]

Post: # 856Post Darren
Sat Apr 14, 2012 9:23 am

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

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

Email using API [shell32.dll]

Post: # 857Post Marco
Sat Apr 14, 2012 3:42 pm

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?")


Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

Email using API [shell32.dll]

Post: # 858Post Marco
Sat Apr 14, 2012 5:36 pm

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

Darren
Posts: 63
Joined: Wed May 11, 2011 11:55 am

Email using API [shell32.dll]

Post: # 859Post Darren
Sun Apr 15, 2012 10:21 am

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

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

Email using API [shell32.dll]

Post: # 860Post Marco
Sun Apr 15, 2012 3:38 pm

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?

Darren
Posts: 63
Joined: Wed May 11, 2011 11:55 am

Email using API [shell32.dll]

Post: # 861Post Darren
Mon Apr 16, 2012 7:59 am

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

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

Email using API [shell32.dll]

Post: # 862Post Marco
Mon Apr 16, 2012 8:21 pm

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

Darren
Posts: 63
Joined: Wed May 11, 2011 11:55 am

Email using API [shell32.dll]

Post: # 863Post Darren
Wed Apr 18, 2012 9:09 am

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

Post Reply