curl -X POST -d "{\"@odata.type\":\"#Microsoft.OutlookServices.Message\",\"Subject\":\"Have you seen this new Mail REST API\",\"Importance,\"Body\":{\"ContentType\":\"Text\",\"Content\":\"It looks awesome\"},\"ToRecipients\":[\"Name\":\"Hope Gross\",\"Address\":\"hope@contoso.com\"}]}" https://outlook.office365.com/api/v1.0/me/sendmail --header "Content-Type:application/json" --insecure --verbose --user "user@domain.com:password"
我收到以下错误:
* Hostname was NOT found in DNS cache
* Trying 132.245.160.44...
* Connected to outlook.office365.com (132.245.160.44) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using ECDHE-RSA-AES256-SHA384
* Server certificate:
* subject: C=US; ST=Washington; L=Redmond; O=Microsoft Corporation; OU=Exchange; CN=outlook.com
* start date: 2014-07-24 18:34:15 GMT
* expire date: 2016-07-23 18:34:15 GMT
* issuer: C=US; ST=Washington; L=Redmond; O=Microsoft Corporation; OU=Microsoft IT; CN=Microsoft IT SSL SHA1
* SSL certificate verify ok.
* Server auth using Basic with user 'user@domain.com'
> POST /api/v1.0/me/sendmail HTTP/1.1
> Authorization: Basic ZmFpemFsLmJoQGZvY3VzaXRlLmNvbTpBRkJIQDc2NzU=
> User-Agent: curl/7.35.0
> Host: outlook.office365.com
> Accept: */*
> Content-Type:application/json
> Content-Length: 247
>
* upload completely sent off: 247 out of 247 bytes
< HTTP/1.1 400 Bad Request
< Cache-Control: private
< Content-Type: text/html
* Server Microsoft-IIS/8.0 is not blacklisted
< Server: Microsoft-IIS/8.0
< request-id: d12eac31-32c2-458f-a70c-ff44e57c44ef
< Set-Cookie: ClientId=UHHCPWIEOIUVFTQNTG; expires=Wed, 28-Oct-2015 07:02:23 GMT; path=/; HttpOnly
< X-CalculatedBETarget: sixpr02mb0638.apcprd02.prod.outlook.com
< X-MS-Credentials-Expire: 13
< OData-Version: 4.0
< X-DiagInfo: SIXPR02MB0638
< X-BEServer: SIXPR02MB0638
< X-AspNet-Version: 4.0.30319
< Set-Cookie: exchangecookie=983848404bbc4c26bb86bda3b3281937; expires=Wed, 28-Oct-2015 07:02:28 GMT; path=/; HttpOnly
< Set-Cookie: X-BackEndCookie2=user@domain.com=u56Lnp2ejJqByJ2bzprLzs/Sz5nNmtLLzJzH0sfHnc/SxpvLx5vLzMrHyZvMgZmQnIqMloua0ZyQkoHNz87L0s7O0s3Iq8/Ixc/NxczNgZ6PnI+Nm8/N0Y+NkJvRkIqLk5CQlNGckJI=; expires=Thu, 27-Nov-2014 07:02:32 GMT; path=/api; secure; HttpOnly
< Set-Cookie: X-BackEndCookie=user@domain.com=u56Lnp2ejJqByJ2bzprLzs/Sz5nNmtLLzJzH0sfHnc/SxpvLx5vLzMrHyZvMgZmQnIqMloua0ZyQkoHNz87L0s7O0s3Iq8/Ixc/NxczN; expires=Thu, 27-Nov-2014 07:02:32 GMT; path=/api; secure; HttpOnly
< X-Powered-By: ASP.NET
< X-FEServer: SIXPR06CA013
< Date: Tue, 28 Oct 2014 07:02:32 GMT
< Content-Length: 11
<
* Connection #0 to host outlook.office365.com left intact
Bad Request
我已经在互联网上搜索过堆栈流,但类似的问题我找不到答案。
我怎样才能创造&amp;使用CURL发送邮件?我也在Linux上测试了它,但结果相同。
答案 0 :(得分:1)
我已经找到了解决方案
以下是工作代码:
curl -X POST -d '{"Message":{"Subject": "Have you seen this new Mail REST API?","Importance": "High","Body": {"ContentType": "HTML","Content": "It looks awesome!"},"ToRecipients": [{"EmailAddress": {"Name": "Ahmad Faizal B H","Address": "ahmadfaizalbh726@gmail.com"}}]}}' https://outlook.office365.com/ews/odata/Me/sendmail --header "Content-Type:application/json" --insecure --verbose --user "user@domain:password"