COMate Plus and mail attachments

Just starting out? Need help? Post your questions and find answers here.
leodh
Enthusiast
Enthusiast
Posts: 164
Joined: Sun Nov 06, 2005 6:07 am
Location: Perth Western Australia

COMate Plus and mail attachments

Post by leodh »

Hi,

I was trying to find out if COMate Plus is able to make Outlook send an Email with an attachment.

At the moment I am using a SMTP gateway server it works fine only about 10 lines of code and the SMTP lib, however the IT people have chucked a wobbly because its on the wrong side of the firewall and my program could be used to send spam. The people I need to send the attachment to are all internal.

The IT people have said that I should use Outlook but we can not get Outlook to send Emails with attachments. we have tried the Runprogram() and ShellExecute_(null,null, "mailto:me@world.com?Subject=MailSubject", Null, Null, #SW_SHOWNORMAL) with all the cominations of Attach file we could find.

Any ideas or examples would be great.
Regards
Leo
User avatar
graves
Enthusiast
Enthusiast
Posts: 160
Joined: Wed Oct 03, 2007 2:38 pm
Location: To the deal with a pepper

Post by graves »

Hi,
I've tried to use MAPI with OUTLOOK, but it's very complex. I'm abandoned it at the moment, moreover, PureSMTP is not enough.

I'm using now BLAT (www.blat.net), with a lot of features and a dll that can be used in your program (you only need a SMTP server, and you can attach files as "inline" files or extenal files):

Code: Select all

  Import "Blat.lib"
    Blat_Send(Emailstring.s) As "_Send@4"
  EndImport

  allopt.s = "some needed options of blat (see syntaxt.txt)"
  if Blat_Send(allopt) <> 0
     MessageRequester("Error","Mail not send")
  endif

Code: Select all

Blat Return Codes 
0       OK

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.
        File name (message text) not given
        Bad argument given

2       The server actively denied our connection.
        The mail server doesn't like the sender name.
        File (message text) does not exist

3       Error reading the file (message text) or attached file

4       File (message text) not of type FILE_TYPE_DISK

5       Error Reading File (message text)

12      -server or -f options not specified and not found in registry

13      Error opening temporary file in temp directory
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

Code: Select all

XIncludeFile "C:\Programme\PureBasic\Include\COMatePlus.pbi" 

Define.COMateObject  OutlookObject.COMateObject, olMsg.COMateObject

sub.s="*** Attachment ***"
standard.s= "Hello"
tomail.s="leodh@mail.at"
add.s=#PB_Compiler_Home+"PureBasic.chm"

OutlookObject = COMate_CreateObject("Outlook.Application") 
If OutlookObject 

  olMsg = OutlookObject\GetObjectProperty("CreateItem(0)") 
   If olMsg 
    olMsg\SetProperty("to='"+tomail+"'") 
    olMsg\SetProperty("Subject='"+sub+"'") 
    olMsg\SetProperty("Body='"+standard+"'") 
    
   If FileSize(add)<>-1
    olMsg\Invoke("Attachments\Add('"+add+"')")
   EndIf
    
    olMsg\Invoke("Display") 
    olMsg\Release() 
    Else 
      MessageRequester("Sorry", COMate_GetLastErrorDescription()) 
  EndIf 
OutlookObject\Release()  
Else 
  MessageRequester("Sorry - CreateObject", COMate_GetLastErrorDescription()) 
EndIf
PureBasic for Windows
leodh
Enthusiast
Enthusiast
Posts: 164
Joined: Sun Nov 06, 2005 6:07 am
Location: Perth Western Australia

Post by leodh »

@ Marco2007

Bloody marvellous :D , you don't know how much this helps, now for more help :lol: , is it posible to send the mail without having outlook displayed ( the user not see the mail )

Thanks again.
Regards
Leo
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

Code: Select all

olMsg\Invoke("Display")
->

Code: Select all

olMsg\Invoke("Send") 
PureBasic for Windows
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Be careful with your body text; COMatePLUS treats ' (single quote) characters as special cases!

You need to use a $0027 escape code if you require single-quotes within your text.

Code: Select all

standard = ReplaceString(standard, "'", "$0027")
I may look like a mule, but I'm not a complete ass.
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

Good to know (because I haven`t ever needed a single Quote) :D
PureBasic for Windows
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Not even an apostrophe?
I may look like a mule, but I'm not a complete ass.
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

I use Comate and Outlook only at work -> only a short fixed Standard-text with Signatur, which I never have changed (Thank you for...blabla. I hope blabla) - a pdf is attached with the important things....-> At home I press "new Mail", when I write something :-)
PureBasic for Windows
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Ah well, good to know anyhow because this is a general COMatePLUS rule of thumb when passing strings.

ADOmate does the string replace automatically (ADOmate of course uses COMatePLUS) and it is always something to keep in mind! :)
I may look like a mule, but I'm not a complete ass.
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

AdoMate...hey, thanks for the hint! I don`t know, why I never tried that :oops:
...Because you know on what I´m working!
PureBasic for Windows
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Cannot find the include file

Post by SkyManager »

Hi all,

I cannot find the include sub-directory under pure basic directory folder.

Where can I get the COMatePlus.pbi?
Post Reply