SET PROCEDURE TO D:\AHSAN\TEST2 #DEFINE cret Chr(13)+Chr(10) #DEFINE dret cret+cret PRIVATE obj obj = CreateObject("MapiSendMail") WITH obj * though the Sender object is implemented I never managed to make it * something else but the default address for the local email client .AddSender("A.A.", "someone@somwhere.mail") * add one or more recipients * note that the following ones will not work, just an example .AddRecipient("Chivas Regal", "info@chivasregal.mail") .AddRecipient("Jim Beam", "info@.jimbeam.mail") .AddRecipient("John Walker", "info@.johnwalkermail") .AddRecipient("Canadian Club", "info@.canclubmail") .MsgSubject = "Test Message" .MsgBody ="This text will be put into body of your message." + dret +; "You can also use table fields and Text and Edit Boxes." + dret +; "Source:" + cret +; "http://www.news2news.com/vfp" * adding file attachments * make sure that all files are available .AddAttachment("C:\myfiles\Resume\cover.txt") .SndMessage ENDWITHand there is prg D:\AHSAN\TEST2 with following codes
DEFINE CLASS MapiSendMail As Custom #DEFINE SUCCESS_SUCCESS 0 MsgSubject="" MsgBody="" snd=.F. rcp=.F. att=.F. PROCEDURE Init THIS.snd = CreateObject("TRecipients") THIS.rcp = CreateObject("TRecipients") THIS.att = CreateObject("TAttachments") PROCEDURE SndMessage IF Not THIS.ValidMessage() RETURN .F. ENDIF LOCAL lcMapiMessage, loSubject, loBody, ii, lnResult, lcStoredPath loSubject = CreateObject("PChar", THIS.MsgSubject) loBody = CreateObject("PChar", THIS.MsgBody) lcStoredPath = SYS(5) + SYS(2003) * assembling MapiMessage structure lcMapiMessage = num2dword(0) +; num2dword(loSubject.getAddr()) + num2dword(loBody.getAddr()) +; num2dword(0) + num2dword(0) + num2dword(0) + num2dword(0) +; num2dword(THIS.snd.getAddr()) +; num2dword(THIS.rcp.ItemCount) + num2dword(THIS.rcp.GetAddr()) +; num2dword(THIS.att.ItemCount) +; num2dword(Iif(THIS.att.ItemCount=0, 0,THIS.att.GetAddr())) DECLARE INTEGER MAPISendMail IN mapi32; INTEGER lhSession, INTEGER ulUIParam, STRING @lpMessage,; INTEGER flFlags, INTEGER ulReserved lnResult = MAPISendMail(0, 0, @lcMapiMessage, 8, 0) SET DEFAULT TO (lcStoredPath) do case case lnResult = 1 * 1 MAPI_E_USER_ABORT case lnResult = 2 * 2 MAPI_E_FAILURE messagebox("Failure while sending email.") case lnResult = 3 * 3 MAPI_E_LOGIN_FAILURE messagebox("Login failure on email account.") case lnResult = 5 * 5 MAPI_E_INSUFFICIENT_MEMORY messagebox("Insufficient memory to carry out email operation.") case lnResult = 6 * 6 MAPI_E_ACCESS_DENIED messagebox("Access denied while executing email operation.") case lnResult = 9 * 9 MAPI_E_TOO_MANY_FILES messagebox("Too many files to carry out email operation.") case lnResult = 10 *10 MAPI_E_TOO_MANY_RECIPIENTS messagebox("Too many recipients to carry out email operation.") case lnResult = 14 *14 MAPI_E_UNKNOWN_RECIPIENT messagebox("Unknown recipient(s). Email will not be sent.") case lnResult = 15 *15 MAPI_E_BAD_RECIPTYPE messagebox("Bad recipient(s). Email will not be sent.") case lnResult = 18 *18 MAPI_E_TEXT_TOO_LARGE messagebox("Text is too large to carry out email operation.") otherwise * 0 = Success endcase RETURN (lnResult=0) && sendmessage FUNCTION ValidMessage LOCAL lValid lValid = THIS.rcp.ItemCount > 0 And; Not (EMPTY(THIS.MsgSubject) And EMPTY(THIS.MsgBody); And THIS.att.ItemCount=0) IF Not m.lValid IF THIS.rcp.ItemCount = 0 = MessageB ("The outgoing message is invalid." + Chr(13) +; "Recipients not defined.", 48, " Invalid message data") ELSE = MessageB ("The outgoing message is invalid." + Chr(13) +; "At least one has to be valid: subj, body, attachments.",; 48, " Invalid message data") ENDIF ENDIF RETURN m.lValid PROCEDURE ClearMessage THIS.ClearRecipients THIS.ClearAttachments THIS.MsgBody="" THIS.MsgSubject="" PROCEDURE AddSender (lcSndName, lcSndAddr) #DEFINE MAPI_ORIG 0 IF TYPE("lcSndAddr") <> "C" lcSndAddr = lcSndName ENDIF THIS.snd.AppendItem (MAPI_ORIG, lcSndName, lcSndAddr) PROCEDURE AddRecipient(lcRcpName, lcRcpAddr, To_CC) * To_CC - 1 = To, 2 = CC #DEFINE MAPI_TO 1 #DEFINE MAPI_CC 2 IF TYPE("lcRcpAddr") <> "C" lcRcpAddr = lcRcpName ENDIF if type("To_CC") <> 'N' To_CC = 1 endifWhen I press command1, it shows following error message