1

How can i send mail with MapBasic??

I have already tried this code, but it's not working i used SenMail Application

sub send
dim cmdstr, subj, msg as string

subj = "Hello from MapInfo-L" '  is the email subject
msg = "This is how you use sendemail to send an email" ' is the message text

cmdstr = "sendemail -f  example@gmail.com -t example@gmail.com -u " + subj + " -m " + msg
run program cmdstr
End Sub
1

You can call any .NET method in MapBasic. So write a "mail sending application" in your preferred language, e.g. C# and use this one.

Here is a simple example of a C# class that provides a static method:

namespace MyProduct
{
   class MyWrapper
   {
      public static int ShowMessage(string s)
      {
         System.Windows.Forms.MessageBox.Show(s);
         return 0;
      }
   }
}

Then in MapBasic you call the method like this:

Declare Method ShowMessage
Class "MyProduct.MyWrapper"
Lib "MyAssembly.DLL" (ByVal str As String) As Integer
. . .
Dim retval As Integer
retval = ShowMessage("Here I am")

Sending a mail in C# is only a few lines of code, see examples here: Send e-mail via SMTP using C#

  • can you please explain me, becaus i have nevre worked with c# – senouci Jun 1 '15 at 0:09
  • You don't have to use C#, it was just an example. If you prefer VB.NET (which has very similar syntax like MapBasic) you can use also this. Google for "send mail with vb.net", you will find many examples. Here another guideline how to use .NET assemblies in MapBasic: How to use a method from a .NET assembly in MapBasic? – Wernfried Domscheit Jun 1 '15 at 11:07
0

You can use this process that's calling the ShellExecute WINApi function

Declare Function WAPIShellExecute Lib "shell32.dll" Alias "ShellExecuteA"
    ( ByVal hwnd As Integer         'Can be zero or a pointer to the MapInfo Window
    , ByVal sOperation As String        'Operation to perform on the file
    , ByVal sFile As String         'File to perform the operation on
    , ByVal sParameters As String       'Parameters to send to the file
    , ByVal sDirectory As String        'Default working directory
    , ByVal nShowCmd As Integer     'How to display the application performing the operation
    ) As Integer
    'http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx

Declare Sub Main

Define SW_SHOWNORMAL        1

Sub Main

Dim nResult As Integer,
    sOperation, sFile, sParameters As String

    sOperation  = ""
    sFile       = "mailto:some.name@pb.com?subject=Test Email&body=Good bye"
    sParameters = ""
    nResult = WAPIShellExecute( 0, sOperation, sFile, sParameters, ApplicationDirectory$(), SW_SHOWNORMAL)

End Sub

It will not send the email directly but open up a new email from your default email application and fill out "to", "subject" and "body".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.