Voilà un code que j'ai trouvé un peu ancien ... faut juste trouver pourquoi il marche plus
Code : Tout sélectionner
; Code by the.weavster
; Source http://www.purebasic.fr/english/viewtopic.php?f=13&t=14722&hilit=mapi32
;declare some MAPI constants...
#SUCCESS_SUCCESS = 0
#MAPI_USER_ABORT = 1
#MAPI_E_FAILURE = 2
#MAPI_E_LOGIN_FAILURE = 3
#MAPI_E_DISK_FULL = 4
#MAPI_E_INSUFFICIENT_MEMORY = 5
#MAPI_E_BLK_TOO_SMALL = 6
#MAPI_E_TOO_MANY_SESSIONS = 8
#MAPI_E_TOO_MANY_FILES = 9
#MAPI_E_TOO_MANY_RECIPIENTS = 10
#MAPI_E_ATTACHMMENT_NOT_FOUND = 11
#MAPI_E_ATTACHMENT_OPEN_FAILURE = 12
#MAPI_E_ATTACHMENT_WRITE_FAILURE = 13
#MAPI_E_UNKNOWN_RECIPIENT = 14
#MAPI_E_BAD_RECITYPE = 15
#MAPI_E_NO_MESSAGES = 16
#MAPI_E_INVALID_MESSAGE = 17
#MAPI_E_TEXT_TOO_LARGE = 18
#MAPI_E_INVALID_SESSION = 19
#MAPI_E_TYPE_NOT_SUPPORTED = 20
#MAPI_E_AMBIGUOUS_RECIPIENT = 21
#MAPI_E_MESSAGE_IN_USE = 22
#MAPI_E_NETWORK_FAILURE = 23
#MAPI_E_INVALID_EDITFIELDS = 24
#MAPI_E_INVALID_RECIPS = 25
#MAPI_E_NOT_SUPPORTED = 26
#MAPI_E_NO_LIBRARY = 999
#MAPI_E_INVALID_PARAMETER = 998
#MAPI_ORIG = 0
#MAPI_TO = 1
#MAPI_CC = 2
#MAPI_BCC = 3
#MAPI_UNREAD = 1
#MAPI_RECEIPT_REQUESTED = 2
#MAPI_SENT = 4
#MAPI_LOGON_UI = $00000001
#MAPI_DIALOG = $00000008
;enumerate other constants...
Enumeration
#MAPI32_DLL
EndEnumeration
;define MAPI structures...
Structure MAPIMessage
Reserved.l
Subject.s
NoteText.s
MessageType.s
DateReceived.s
ConversationID.s
Flags.l
Originator.s
RecipCount.l
Recips.l
FileCount.l
Files.l
EndStructure
Structure MAPIRecip
Reserved.l
RecipClass.l
Name.s
Address.s
EIDSize.l
EntryID.s
EndStructure
Structure MAPIFile
Reserved.l
Flags.l
Position.l
PathName.s
FileName.s
FileType.l
EndStructure
;declare global variables...
Global lSession.l
Global ErrorDecsription.s
Global udtMessage.MAPIMessage
Global udtRecip.MAPIRecip
Global udtFile.MAPIFile
;open the MAPI library...
Result.l = OpenLibrary(#MAPI32_DLL,"MAPI32.DLL")
If Result = 0
MessageRequester("Error","Could Not Load MAPI Library",0)
End
EndIf
;set pointers to the required functions...
Global MAPILogOff.l : MAPILogOff = GetFunction(#MAPI32_DLL,"MAPILogoff")
Global MAPILogOn.l : MAPILogOn = GetFunction(#MAPI32_DLL,"MAPILogon")
Global MAPISendMail.l : MAPISendMail = GetFunction(#MAPI32_DLL,"MAPISendMail")
If MAPILogOff And MAPILogOn And MAPISendMail
Else
MessageRequester("Error","Function Did Not Load",0)
CloseLibrary(#MAPI32_DLL)
End
EndIf
;error definition function...
Procedure.s MAPIError(lError.l)
Select lError
Case #MAPI_USER_ABORT
text$ = "MAPI User Cancel"
Case #MAPI_E_FAILURE
text$ = "MAPI Failure"
Case #MAPI_E_LOGIN_FAILURE
text$ = "MAPI Login Failure"
Case #MAPI_E_DISK_FULL
text$ = "MAPI Disk Full"
Case #MAPI_E_INSUFFICIENT_MEMORY
text$ = "MAPI Insufficient Memory"
Case #MAPI_E_BLK_TOO_SMALL
text$ = "MAPI Block Too Small"
Case #MAPI_E_TOO_MANY_SESSIONS
text$ = "MAPI Too Many Sessions"
Case #MAPI_E_TOO_MANY_FILES
text$ = "MAPI Too Many Files"
Case #MAPI_E_TOO_MANY_RECIPIENTS
text$ = "MAPI Too Many Attachments"
Case #MAPI_E_ATTACHMMENT_NOT_FOUND
text$ = "MAPI Attachment Not Found"
Case #MAPI_E_ATTACHMENT_OPEN_FAILURE
text$ = "MAPI Attachment Open Failure"
Case #MAPI_E_ATTACHMENT_WRITE_FAILURE
text$ = "MAPI Attachment Write Failure"
Case #MAPI_E_UNKNOWN_RECIPIENT
text$ = "MAPI Unknown Recipient"
Case #MAPI_E_BAD_RECITYPE
text$ = "MAPI Bad Recipient Type"
Case #MAPI_E_NO_MESSAGES
text$ = "MAPI No Messages"
Case #MAPI_E_INVALID_MESSAGE
text$ = "MAPI Invalid Message"
Case #MAPI_E_TEXT_TOO_LARGE
text$ = "MAPI Text Too Large"
Case #MAPI_E_INVALID_SESSION
text$ = "MAPI Invalid Session"
Case #MAPI_E_TYPE_NOT_SUPPORTED
text$ = "MAPI Type Not Supported"
Case #MAPI_E_AMBIGUOUS_RECIPIENT
text$ = "MAPI Ambiguous Recipient"
Case #MAPI_E_MESSAGE_IN_USE
text$ = "MAPI Message In Use"
Case #MAPI_E_NETWORK_FAILURE
text$ = "MAPI Network Failure"
Case #MAPI_E_INVALID_EDITFIELDS
text$ = "MAPI Invalid Edit Fields"
Case #MAPI_E_INVALID_RECIPS
text$ = "MAPI Invalid Recipients"
Case #MAPI_E_NOT_SUPPORTED
text$ = "MAPI Not Supported"
Case #MAPI_E_NO_LIBRARY
text$ = "MAPI No Library"
Case #MAPI_E_INVALID_PARAMETER
text$ = "MAPI Invalid Parameter"
EndSelect
text$ = text$ + " [Error No: " + Str(lError) + "]"
ProcedureReturn text$
EndProcedure
;connect and send mail function...
Procedure.l SendEMail(UserName.s,Password.s,Recipient.s,Subject.s,Message.s,Attachment.s)
Dim udtRecips.MAPIRecip(0)
Dim udtFiles.MAPIFile(0)
ErrorDecsription = "No Problem"
If Recipient <> "" And Right(Recipient,1) <> ";"
Recipient = Recipient + ";"
EndIf
lRecipientCount.l = CountString(Recipient,";")
If lRecipientCount > 0
Dim udtRecips.MAPIRecip(lRecipientCount)
For k = 0 To lRecipientCount - 1
udtRecips(k)\Reserved = 0
udtRecips(k)\RecipClass = #MAPI_TO
udtRecips(k)\Name = StringField(Recipient,k + 1,";")
udtRecips(k)\Address = ""
udtRecips(k)\EIDSize = 1000
udtRecips(k)\EntryID = ""
Next k
EndIf
If Attachment <> "" And Right(Attachment,1) <> ";"
Attachment = Attachment + ";"
EndIf
lFileCount.l = CountString(Attachment,";")
If lFileCount > 0
Dim udtFiles.MAPIFile(lFileCount)
For k = 0 To lFileCount - 1
udtFiles(k)\Reserved = 0
udtFiles(k)\Flags = 0
udtFiles(k)\Position = 0
udtFiles(k)\PathName = StringField(Attachment,k + 1,";")
udtFiles(k)\FileName = GetFilePart(StringField(Attachment,k + 1,";"))
udtFiles(k)\FileType = 0
Next k
EndIf
udtMessage\Reserved = 0
udtMessage\Subject = Subject
udtMessage\NoteText = Message
udtMessage\MessageType = ""
udtMessage\DateReceived = FormatDate("%yyyy/%mm/%dd %hh:%ii",Date())
udtMessage\ConversationID = ""
udtMessage\Flags = 0
udtMessage\Originator = UserName
udtMessage\RecipCount = lRecipientCount
udtMessage\Recips = @udtRecips()
udtMessage\FileCount = lFileCount
udtMessage\Files = @udtFiles()
lResult.l = CallFunctionFast(MAPILogOn,0,UserName,Password,#MAPI_LOGON_UI,0,@lSession)
If lReturn <> #SUCCESS_SUCCESS
ErrorDecsription = MAPIError(lResult)
ProcedureReturn #False
EndIf
lResult.l = CallFunctionFast(MAPISendMail,lSession,0,udtMessage,0,0) ;could use #MAPI_DIALOG as parameter 4 to display the e-mail
If lResult <> #SUCCESS_SUCCESS
ErrorDecsription = MAPIError(lResult)
ProcedureReturn #False
EndIf
lResult.l = CallFunctionFast(MAPILogOff,lSession,0,0,0)
If lResult <> #SUCCESS_SUCCESS
ErrorDecsription = MAPIError(lResult)
ProcedureReturn #False
EndIf
ProcedureReturn #True
Dim udtRecips.MAPIRecip(0)
Dim udtFiles.MAPIFile(0)
EndProcedure
;give it a little try...
MyAccount.s = InputRequester("User Name","Please Input Your SMTP User Name","")
MyPassword.s = InputRequester("Password","Please Input Your SMTP Password","")
MyRecipients.s = "falsename@falseaddress.com;somebodyelse@falseaddress.com"
MySubject.s = "Subject Goes Here"
MyText.s = "Message Goes Here"
MyAttachments.s = OpenFileRequester("Attachment","*.*","All Files | *.*",0)
lTest.l = SendEMail(MyAccount,MyPassword,MyRecipients,MySubject,MyText,MyAttachments)
If lTest = #True
MessageRequester("Confirmation","EMail Created OK",0)
Else
MessageRequester("Error",ErrorDecsription,0)
EndIf
CloseLibrary(#MAPI32_DLL)
End