1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
| * Public code from Foxpro Forums.
* http://fox.wikis.com/wc.dll?Wiki~SendHotmailMessageFromFoxPro
* Anatoliy Mogylevets
* Hata verirse; MSXML 4.0 Service Pack 2 in yüklü olması gerekiyor.
* provide valid Hotmail or MSN account
DO HotmailSend WITH;
'myself@hotmail.com', 'mypassword',;
'someone@somewhere.com',;
'Check this email', 'This is a test message sent from Hotmail account.'
And here is the procedure:
PROCEDURE HotmailSend(cEmail, cPwd, cRecipient, cSubject, cMsgBody)
#DEFINE cret Chr(13)+Chr(10)
* MSN and Hotmail server URLs
#DEFINE urlMsn "http://oe.msn.msnmail.hotmail.com/cgi-bin/hmdata"
#DEFINE urlHotmail "http://services.msn.com/svcs/hotmail/httpmail.asp"
#DEFINE ccXmlFolders '<'+'?xml version="1.0"?'+'>' + cret +;
'<'+'D:propfind xmlns:D="DAV:" xmlns:h="http://schemas.microsoft.com/hotmail/" ' +;
'xmlns:hm="urn:schemas:httpmail:">' + cret +;
' <'+'D:prop'+'>' + cret +;
' <'+'h:adbar/'+'>' + cret +;
' <'+'hm:contacts/'+'>' + cret +;
' <'+'hm:inbox/'+'>' + cret +;
' <'+'hm:outbox/'+'>' + cret +;
' <'+'hm:sendmsg/'+'>' + cret +;
' <'+'hm:sentitems/'+'>' + cret +;
' <'+'hm:deleteditems/'+'>' + cret +;
' <'+'hm:drafts/'+'>' + cret +;
' <'+'hm:msgfolderroot/'+'>' + cret +;
' <'+'h:maxpoll/'+'>' + cret +;
' <'+'h:sig/'+'>' + cret +;
' <'+'/D:prop'+'>' + cret +;
'<'+'/D:propfind'+'>'
#DEFINE ccSendmsgNode '/D:multistatus/D:response/D:propstat/D:prop/hm:sendmsg'
LOCAL cServer, oHttp, nRespCode
DO CASE
CASE '@hotmail.com' $ LOWER(cEmail)
cServer = urlHotmail
CASE '@msn.com' $ LOWER(cEmail)
cServer = urlMsn
OTHER
? 'Invalid Hotmail account.'
RETURN
ENDCASE
oHttp = CreateObject('MSXML2.ServerXMLHTTP')
WITH oHttp
.Open("PROPFIND", cServer, 0, cEmail, cPwd)
.Send(ccXmlFolders)
nRespCode = VAL(SUBSTR(.GetResponseHeader('X-Dav-Error'), 1,3))
ENDWITH
IF nRespCode <> 200
? 'Could not connect to Hotmail account.'
? 'Request status: ' + LTRIM(STR(oHttp.Status)) + ', ' +;
oHttp.StatusText
RETURN
ENDIF
LOCAL oXml, cSendmsgHref, cMessage
oXml = CreateObject('Microsoft.XMLDOM')
oXml.Load(oHttp.ResponseXml)
cSendmsgHref = oXml.SelectSingleNode(ccSendmsgNode).Text
IF EMPTY(cSendmsgHref)
? 'Could not obtain SendMsg url.'
RETURN
ENDIF
* formatting message
LOCAL cMessage
cMessage = 'MAIL FROM:<' + cEmail + '>' + cret +;
'RCPT TO:<' + cRecipient + '>' + cret +;
'' + cret +;
'From: <' + cEmail + '>' + cret +;
'To: <' + cRecipient + '>' + cret +;
'Subject: ' + cSubject + cret +;
'Date: ' + TTOC(datetime()) + cret +;
'MIME-Version: 1.0' + cret +;
'Content-Type: text/plain;' + cret +;
'X-Mailer: Visual FoxPro applicaiton' + cret +;
'' + cret +;
cMsgBody
WITH oHttp
.Open("POST", cSendmsgHref, 0)
.SetRequestHeader('Content-Type', 'message/rfc821')
.SetRequestHeader('SAVEINSENT', 'f') && do not save in Sent Messages folder
.Send(cMessage)
nRespCode = VAL(SUBSTR(.GetResponseHeader('X-Dav-Error'), 1,3))
ENDWITH
IF nRespCode <> 200
? 'Message has not been sent.'
? 'Request status: ' + LTRIM(STR(oHttp.Status)) + ', ' +;
oHttp.StatusText
? oHttp.GetAllResponseHeaders()
ELSE
? 'Message has been sent successfully.'
ENDIF |