das nachfolgende Programm um personifizierte E-Mails mit Anhang zu versenden, funktioniert.
Nun würde ich gerne mehrere E-Mails (Newsletter) versenden die jedoch automatisch im Outlook-Ordner Ausgänge gespeichert werden sollen, ohne dass für jede E-Mail ein Popup-Fenster für Outlook geöffnet wird.
Ist das überhaupt möglich bzw. was muss ich genau ändern?
Code: Alles auswählen
#pragma library( "ascom10.lib" )
#include "Appevent.ch"
#include "Dmlb.ch"
#include "outlook.ch"
#include "dll.ch"
#include "common.ch"
//--error codes from MAPI.H
#define SUCCESS_SUCCESS 0
#define MAPI_USER_ABORT 1
#define MAPI_E_FAILURE 2
#define MAPI_E_LOGIN_FAILURE 3
#define MAPI_E_DISK_FULL 4
#define MAPI_E_INSUFFICIENT_MEMORY 5
#define MAPI_E_ACCESS_DENIED 6
#define MAPI_E_TOO_MANY_SESSIONS 8
#define MAPI_E_TOO_MANY_FILES 9
#define MAPI_E_TOO_MANY_RECIPIENTS 10
#define MAPI_E_ATTACHMENT_NOT_FOUND 11
#define MAPI_E_ATTACHMENT_OPEN_FAILURE 12
#define MAPI_E_ATTACHMENT_WRITE_FAILURE 13
#define MAPI_E_UNKNOWN_RECIPIENT 14
#define MAPI_E_BAD_RECIPTYPE 15
#define MAPI_E_NO_MESSAGES 16
#define MAPI_E_INVALID_MESSAGE 17
#define MAPI_E_TEXT_TOO_LARGE 18
#define MAPI_E_INVALID_SESSION 19
#define MAPI_E_TYPE_NOT_SUPPORTED 20
#define MAPI_E_AMBIGUOUS_RECIPIENT 21
#define MAPI_E_MESSAGE_IN_USE 22
#define MAPI_E_NETWORK_FAILURE 23
#define MAPI_E_INVALID_EDITFIELDS 24
#define MAPI_E_INVALID_RECIPS 25
#define MAPI_E_NOT_SUPPORTED 26
//--ID´s for Message items
#define ID_SUBJECT 0
#define ID_MESSAGE 1
#define ID_MESSAGE_TYPE 2
#define ID_DATE 3
#define ID_ORIGINATOR_NAME 4
#define ID_ORIGINATOR_ADRESS 5
#define ID_RECIPIENT_NAME 6
#define ID_RECIPIENT_ADRESS 7
#define ID_ATTACHMENT_PATHNAME 8
#define ID_ATTACHMENT_FILENAME 9
#define ID_CONVERSATION_ID 10
//--Message Flags
#define NOFLAG 0
#define FLAG_UNREAD 1
#define FLAG_RECEIPT_REQUESTED 2
#define FLAG_SENT 4
//--SKIP Flags
#define SKIP_ONLY 0
#define DELETE_THEN_SKIP 1
//--Function Handles
STATIC snDllHandle := 0
STATIC scDLLSocMapiIsInit := "" //Determines if MAPI is already initialized
STATIC scDLLSocMapiInit := "" //Initializes MAPI
STATIC scDLLSocMapiDeInit := "" //DeInitializes MAPI
STATIC scDLLSocMapiIsLoggedOn:= "" //Dertermines if already logged onto a MAPI session.
STATIC scDLLSocMapiLogon := "" //Loggs onto a MAPI session
STATIC scDLLSocMapiLogoff := "" //Loggs off from a MAPI session
STATIC scDLLSocMapiSendMail := "" //Opens the mail editor with some preset Data.
STATIC scDLLSocMapiPostMail := "" //Directly puts a mail in the outbox (without a Dialog)
STATIC scDLLInboxOpen := "" //Initializes for further actions with the Inbox
STATIC scDLLInboxClose := "" //Frees memory that has been allocated with the inbox functions
STATIC scDLLInboxGoTop := "" //Positions the "Record pointer" to the first message in the inbox and reads it.
STATIC scDLLInboxSkip := "" //Skips to the next message in the inbox and reads it.
STATIC scDLLAskFlag := "" //Determines the Flags of a message (unread, Receipt requested, sent)
STATIC scDLLAskBufferSize := "" //Determines, how much buffer must be allocated for the following "StuffBuffer" call.
STATIC scDLLStuffBuffer := "" //Stuffs the buffer with a string for the desired message-element.
STATIC scDLLCountRecipients := "" //Counts the number of recipients for the current message.
STATIC scDLLCountAttachments := "" //counts the number of attachments for the current message.
STATIC scDLLSaveAttachments := "" //Stores all attachments of a message to temporary files.
STATIC scDLLMarkAsRead := "" //Marks current message as read
// PRG VZerstna fr gleichzeitige Emailausudrucke
Procedure emailout
//if not already logged on, Logon to new MAPI session
if DllExecuteCall( scDLLSocMapiIsLoggedOn ) == 0
if (nErr := DllExecuteCall(scDLLSocMapiLogon)) != SUCCESS_SUCCESS
NotifyError( nErr )
return
endif
endif
set default to (substr(FESTWO,1,1) + ":")
set path to (substr(FESTWO,1,1) + ":")
// set default to (verzword)
// SET PATH to (verzword)
set default to (verzexe)
SET PATH to (verzexe)
// Grundeinstellungen erfolgen in Global*.PRG (MAIN) laut Programm-Anmeldung User
// Emailadresse Empf„nger = cAdresses eventuell ändern
// public betrmail = cSubject eventuell ändern
// public Anlage1 = cAttachments eventuell ändern
// z.B. cAttachments cAttachments := (verzword)+ "/BUEPLogo.PDF"
// w„hlt die Anzahl der Anh„nge aus, je nach Emailart mit 1 2 oder 3 Anhängen
// Public AnzAnhaenge ANzahl in VZerstna vorgegeben
// ist die Variable die die Anhänge für
// Public Anhangx
// wenn Nutzer geprüft und ok Variablen belegen
// public Emilwer Emailadresse Empf„nger = cAdresses
// Vorbelegung für Anrede und Grüße in Email
// public PERSWER
// public betrmail = cSubject
// public Anlage = cAttachments
// public Anlage = cAttachments
// Public infmess0 Text in mail = cMessage Sehr geehrte Damen und Herren oder Hallo
// Public infmess1 Text um was es geht
// Public infmess2 Grußformel Mit freundlichen Grüßen bzw. Viele Grüße
// Public infmess3 Geschäftsführer
// Public infmess3b Unterzeichner
// Public infmess3c Abteilung
// Public infmess4 Name Firma
// Public infmess5 Firmensitz
// Public infmess6 Web und EMail
// Public infmess7 bei GMBH Registergericht und Nummer
// Public infmess8 Registrierungsstelle des Vermittlers
// Public infmess9 www.vermittlerregister.info
// Public infmess10 Art der Tätigkeit und Nummer
// Public infmess11 Anschrift Gewerbeamt
// Public infmess12 Versicherung und Nummer
SendMail()
// Diese Programmausfhrung kann deaktiviert werden, wenn alles läuft
ProcessInbox()
//Logoff from MAPI session
DllExecuteCall(scDLLSocMapiLogoff)
// Rückstellung Anrede auf Standard
store "S" to perswer
return
// EMail-Senden durch Outlook
// Init PROCEDURE //
INIT PROCEDURE SocMapiI()
//Load DLL
snDllHandle := DllLoad( "SocMapi.Dll" )
if snDllHandle == 0
MsgBox("SOCMAPI.DLL not found!")
?
?
? "SOCMAPI.DLL nicht gefunden"
?
wait
QUIT
endif
//Get Function handles from DLL.
scDLLSocMapiIsInit := DllPrepareCall( snDllHandle, DLL_STDCALL, "SocMapiIsInit" )
scDLLSocMapiInit := DllPrepareCall( snDllHandle, DLL_STDCALL, "SocMapiInit" )
scDLLSocMapiDeInit := DllPrepareCall( snDllHandle, DLL_STDCALL, "SocMapiDeInit" )
scDLLSocMapiIsLoggedOn:= DllPrepareCall( snDllHandle, DLL_STDCALL, "SocMapiIsLoggedOn" )
scDLLSocMapiLogon := DllPrepareCall( snDllHandle, DLL_STDCALL, "SocMapiLogon" )
scDLLSocMapiLogoff := DllPrepareCall( snDllHandle, DLL_STDCALL, "SocMapiLogoff" )
scDLLSocMapiSendMail := DllPrepareCall( snDllHandle, DLL_STDCALL, "SocMapiSendMail" )
scDLLSocMapiPostMail := DllPrepareCall( snDllHandle, DLL_STDCALL, "SocMapiPostMail" )
scDLLInboxOpen := DllPrepareCall( snDllHandle, DLL_STDCALL, "InboxOpen" )
scDLLInboxClose := DllPrepareCall( snDllHandle, DLL_STDCALL, "InboxClose" )
scDLLInboxGoTop := DllPrepareCall( snDllHandle, DLL_STDCALL, "InboxGoTop" )
scDLLInboxSkip := DllPrepareCall( snDllHandle, DLL_STDCALL, "InboxSkip" )
scDLLAskFlag := DllPrepareCall( snDllHandle, DLL_STDCALL, "AskFlag" )
scDLLAskBufferSize := DllPrepareCall( snDllHandle, DLL_STDCALL, "AskBufferSize" )
scDLLStuffBuffer := DllPrepareCall( snDllHandle, DLL_STDCALL, "StuffBuffer" )
scDLLCountRecipients := DllPrepareCall( snDllHandle, DLL_STDCALL, "CountRecipients" )
scDLLCountAttachments := DllPrepareCall( snDllHandle, DLL_STDCALL, "CountAttachments" )
scDLLSaveAttachments := DllPrepareCall( snDllHandle, DLL_STDCALL, "SaveAttachments" )
scDLLMarkAsRead := DllPrepareCall( snDllHandle, DLL_STDCALL, "MarkAsRead" )
//initialize MAPI
if DllExecuteCall( scDLLSocMapiIsInit ) == 0
nErr := DllExecuteCall( scDLLSocMapiInit )
if nErr != 0
MsgBox("MAPI could not be initialized! Errorcode: " + ALLTRIM(str(nErr)) )
QUIT
endif
endif
return
//*************************************************************************** Init Procedure
//*************************************************************************** DemoSendMail
// SendMail //
//////////////////
// remarks:
// If no Flags are desired, use NOFLAG (don´t leave that uninitialised)
// Combine flags with "+" e.g.:
// nFlag := FLAG_RECEIPT_REQUESTED + FLAG_UNREAD + FLAG_SENT
// However for sending mails, actually only FLAG_RECEIPT_REQUESTED is useful.
PROCEDURE SendMail()
// "Mxxxx@T-Online.de;" + "info@Mxxxxx.de;" + "CC:Mxxxx@T-Online.de;" + "BCC:info@Sxxxx.de"
Local cAdresses := (Emilwer)
local cSubject := (Betrmail)
local cMessage := (infmess0)+(Chr(13))+(Chr(13))+(infmess1)+(Chr(13))+(infmess2)+(Chr(13))+(Chr(13))+(infmesss)+(Chr(13))+(Chr(13))+(infmess3b)+(Chr(13))+(infmess3c)+(Chr(13))+(Chr(13))+(infmess4)+(Chr(13))+(infmess3)+(Chr(13))+(infmess5)+(Chr(13))+(Chr(13))+(infmess6)+(Chr(13))+(Chr(13))+(infmess7)+(Chr(13))+(Chr(13))+(infmess8a)+(Chr(13))+(infmess8)+(Chr(13))+(infmess9)+(Chr(13))+(Chr(13))+(infmess10)+(Chr(13))+(Chr(13))+(infmess11)+(Chr(13))+(Chr(13))+(infmess12)
// das ist das Muster => wichtig in Anfhrungszeichen Local cAttachments := "C:\MBNETZ\MAB\DRUWORD\BUEPOB.PDF;C:\MBNETZ\MAB\DRUWORD\BUEPLogo.PDF"
Local cAttachments := &Anhangx
local nFlag := NOFLAG
local nErr
BEGIN SEQUENCE
// set default to (verzword)
// SET PATH to (verzword)
set default to (verzexe)
SET PATH to (verzexe)
//-- Pop up maileditor
MsgBox("mail will be send with Maileditor popping up")
nErr := DllExecuteCall( scDLLSocMapiSendMail , cAdresses , cSubject , cMessage, cAttachments , nFlag)
if nErr != SUCCESS_SUCCESS .and. nErr != MAPI_USER_ABORT
break nErr
endif
//-- Store mail directly to outbox
MsgBox("mail will be stored directly to outbox")
nErr := DllExecuteCall( scDLLSocMapiPostMail , cAdresses , cSubject , cMessage , cAttachments , nFlag)
if nErr != SUCCESS_SUCCESS
break nErr
endif
// MsgBox("mail successfully stored to outbox")
RECOVER USING nErr
NotifyError (nErr)
END SEQUENCE
return
//*************************************************************************** DemoSendMail
//*************************************************************************** DemoProcessInbox
// DemoProcessInbox //
//////////////////////
PROCEDURE ProcessInbox()
local nErr
local nMsg := 0
local i
local cSubject, cMessage , cMessageType, cDate
local cOriginatorName , cOriginatorAdress
local cConversationID
local nRead, nRecipRequest, nSent
local nRecipients, nAttachments
local aRecipName , aRecipAdress
local aAttachPath, aAttachFile
BEGIN SEQUENCE
// MsgBox("mails from the inbox folder will be processed!")
//Open (i.e. initialize) Inbox folder, goto Top message
if (nErr := DllExecuteCall( scDLLInboxOpen )) != SUCCESS_SUCCESS
break nErr
endif
if (nErr := DllExecuteCall( scDLLInboxGoTop )) != SUCCESS_SUCCESS
break nErr
endif
//--loop for every message in the inbox
do while .T.
//--Get Flags from Message
nRead := DllExecuteCall( scDLLAskFlag , FLAG_UNREAD )
nRecipRequest := DllExecuteCall( scDLLAskFlag , FLAG_RECEIPT_REQUESTED )
nSent := DllExecuteCall( scDLLAskFlag , FLAG_SENT )
//--Get all Message items for current message
cSubject := GetMessageItem ( ID_SUBJECT , nil )
cMessage := GetMessageItem ( ID_MESSAGE , nil )
cMessageType := GetMessageItem ( ID_MESSAGE_TYPE , nil )
cDate := GetMessageItem ( ID_DATE , nil )
cOriginatorName := GetMessageItem ( ID_ORIGINATOR_NAME , nil )
cOriginatorAdress := GetMessageItem ( ID_ORIGINATOR_ADRESS, nil )
cConversationID := GetMessageItem ( ID_CONVERSATION_ID , nil )
//--Get all Recipients names/adresses to Array
nRecipients := DllExecuteCall ( scDLLCountRecipients )
aRecipName := {}
aRecipAdress := {}
for i=1 to nRecipients
AADD( aRecipName , GetMessageItem ( ID_RECIPIENT_NAME , i ))
AADD( aRecipAdress, GetMessageItem ( ID_RECIPIENT_ADRESS , i ))
next
//--In case there are Attachments, store them to Temp files, get all Filenames/pathnames to Array
nAttachments := DllExecuteCall ( scDLLCountAttachments )
aAttachFile := {}
aAttachPath := {}
if nAttachments > 0
if (nErr := DllExecuteCall( scDllSaveAttachments)) != SUCCESS_SUCCESS
break nErr
endif
for i=1 to nAttachments
AADD( aAttachFile , GetMessageItem ( ID_ATTACHMENT_FILENAME , i ))
AADD( aAttachPath , GetMessageItem ( ID_ATTACHMENT_PATHNAME , i ))
next
endif
//-- Display on the screen
nMsg++
? ""
? "Mailnr.: " + ALLTRIM(STR(nMsg))
? "--------Flags--------"
? LEFT("Msg unread : " + ALLTRIM(STR(nRead )) , 78)
? LEFT("Receipt requested : " + ALLTRIM(STR(nRecipRequest)) , 78)
? LEFT("Msg sent : " + ALLTRIM(STR(nSent )) , 78)
? "---------------------"
? LEFT("Subject : " + cSubject , 78)
? LEFT("Message : " + cMessage , 78)
? LEFT("Mess.Type: " + cMessageType , 78)
? LEFT("Rec.Date : " + cDate , 78)
? LEFT("Orig.Name: " + cOriginatorName , 78)
? LEFT("Orig.Adr : " + cOriginatorAdress, 78)
? LEFT("Conv-ID : " + cConversationID , 78)
for i=1 to nRecipients
? LEFT("Recip-Name-" + ALLTRIM(STR(i)) + ": " + aRecipName[i] , 78)
? LEFT("Recip-Adr -" + ALLTRIM(STR(i)) + ": " + aRecipAdress[i] , 78)
next
for i=1 to nAttachments
? LEFT("Att.File -" + ALLTRIM(STR(i)) + ": " + aAttachFile [i] , 78)
? LEFT("Att.Path -" + ALLTRIM(STR(i)) + ": " + aAttachPath [i] , 78)
next
? REPL("-",78)
// MsgBox("Message " + ALLTRIM(STR(nMsg)))
//--Mark message as read.
if (nErr := DllExecuteCall( scDLLMarkAsRead )) != SUCCESS_SUCCESS
break nErr
endif
//-- Skip to next message without deleting, Set DELETE_THEN_SKIP flag if current message
//-- should be deleted before skipping
nErr := DllExecuteCall (scDLLInboxSkip , SKIP_ONLY )
if nErr == SUCCESS_SUCCESS
loop
elseif nErr == MAPI_E_NO_MESSAGES
exit
else
break nErr
endif
enddo
// MsgBox("All Messages processed")
RECOVER USING nErr
NotifyError(nErr)
END SEQUENCE
//--Finally close inbox, i.e free memory.
DllExecuteCall(scDLLInboxClose)
return
//*************************************************************************** DemoProcessInbox
//*************************************************************************** GetMessageItem
// GetMessageItem //
/////////////////////
FUNCTION GetMessageItem ( nID , nItemPos )
local nBufSize
local cBuffer
local nErr
nBufSize := DllExecuteCall( scDLLAskBufferSize , nID , nItemPos )
cBuffer := SPACE(nBufSize)
nErr := DllExecuteCall( scDLLStuffBuffer , nID , nItemPos , @cBuffer , nBufSize)
if nErr != SUCCESS_SUCCESS
break nErr
endif
return cBuffer
//*************************************************************************** GetMessageItem
//*************************************************************************** NotifyError
// NotifyError //
/////////////////
PROCEDURE NotifyError( nErr )
local cErr
do case
case nErr==SUCCESS_SUCCESS ; cErr := "Successful!"
case nErr==MAPI_USER_ABORT ; cErr := "USER_ABORT "
case nErr==MAPI_E_FAILURE ; cErr := "FAILURE "
case nErr==MAPI_E_LOGIN_FAILURE ; cErr := "LOGIN_FAILURE "
case nErr==MAPI_E_DISK_FULL ; cErr := "DISK_FULL "
case nErr==MAPI_E_INSUFFICIENT_MEMORY ; cErr := "INSUFFICIENT_MEMORY "
case nErr==MAPI_E_ACCESS_DENIED ; cErr := "ACCESS_DENIED "
case nErr==MAPI_E_TOO_MANY_SESSIONS ; cErr := "TOO_MANY_SESSIONS "
case nErr==MAPI_E_TOO_MANY_FILES ; cErr := "TOO_MANY_FILES "
case nErr==MAPI_E_TOO_MANY_RECIPIENTS ; cErr := "TOO_MANY_RECIPIENTS "
case nErr==MAPI_E_ATTACHMENT_NOT_FOUND ; cErr := "ATTACHMENT_NOT_FOUND "
case nErr==MAPI_E_ATTACHMENT_OPEN_FAILURE ; cErr := "ATTACHMENT_OPEN_FAILURE "
case nErr==MAPI_E_ATTACHMENT_WRITE_FAILURE; cErr := "ATTACHMENT_WRITE_FAILURE"
case nErr==MAPI_E_UNKNOWN_RECIPIENT ; cErr := "UNKNOWN_RECIPIENT "
case nErr==MAPI_E_BAD_RECIPTYPE ; cErr := "BAD_RECIPTYPE "
case nErr==MAPI_E_NO_MESSAGES ; cErr := "NO_MESSAGES "
case nErr==MAPI_E_INVALID_MESSAGE ; cErr := "INVALID_MESSAGE "
case nErr==MAPI_E_TEXT_TOO_LARGE ; cErr := "TEXT_TOO_LARGE "
case nErr==MAPI_E_INVALID_SESSION ; cErr := "INVALID_SESSION "
case nErr==MAPI_E_TYPE_NOT_SUPPORTED ; cErr := "TYPE_NOT_SUPPORTED "
case nErr==MAPI_E_AMBIGUOUS_RECIPIENT ; cErr := "AMBIGUOUS_RECIPIENT "
case nErr==MAPI_E_MESSAGE_IN_USE ; cErr := "MESSAGE_IN_USE "
case nErr==MAPI_E_NETWORK_FAILURE ; cErr := "NETWORK_FAILURE "
case nErr==MAPI_E_INVALID_EDITFIELDS ; cErr := "INVALID_EDITFIELDS "
case nErr==MAPI_E_INVALID_RECIPS ; cErr := "INVALID_RECIPS "
case nErr==MAPI_E_NOT_SUPPORTED ; cErr := "NOT_SUPPORTED "
otherwise ; cErr := "Unknown Mapi Error"
endcase
// Zeile kann deaktiviert werden
// MsgBox(cErr)
return