0

I would like to set my "message of absence" in strato webmail programmatically. For that I open the developer tools (firefox) and I login via strato webmail and set the "message of absence". I get the curl request from the developer console and I rebuild this as a php code:

$myJson = '
{
    "actioncmds": [
        {
            "addresses": [
                "mail@domain.de"
            ],
            "days": "7",
            "id": "vacation",
            "subject": "My Subject",
            "text": "My Message"
        }
    ],
    "active": true,
    "flags": [
        "vacation"
    ],
    "id": 5,
    "position": 0,
    "rulename": "Abwesenheitsbenachrichtigung",
    "test": {
        "id": "allof",
        "tests": [
            {
                "comparison": "ge",
                "datepart": "date",
                "datevalue": [
                    1672272000000
                ],
                "id": "currentdate",
                "zone": "+0100"
            },
            {
                "comparison": "le",
                "datepart": "date",
                "datevalue": [
                    1672876800000
                ],
                "id": "currentdate",
                "zone": "+0100"
            }
        ]
    }
}';



function stratoCurl( $url, $type, $parameter ) {
    
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS);
    curl_setopt($ch, CURLOPT_ENCODING, '');
    curl_setopt($ch, CURLOPT_POSTFIELDS,  $parameter);
    curl_setopt($ch, CURLOPT_HTTPHEADER, 
        array (
            'Content-Type: application/x-www-form-urlencoded'
        ),
    );
    
    $response = json_decode(curl_exec($ch), true);
    curl_close($ch);
    return $response;
}


$stratoLogin = stratoCurl("https://webmail.strato.de/appsuite/api/login", "POST", http_build_query(array (
    "action"                        =>  "login",
    "name"                          =>  "myUserName",
    "password"                      =>  "myPassword"
)));



$setMessage = stratoCurl("https://webmail.strato.de/appsuite/api/mailfilter/v2?action=update&session=".$stratoLogin['session'], "PUT", $myJson);

echo '<pre>';
print_r($stratoLogin);
print_r($setMessage);
echo '</pre>';

Result:

Array
(
    [session] => MY_SESSION_ID
    [user] => myUsername
    [user_id] => 9
    [context_id] => 52515441
    [locale] => de_DE
)
Array
(
    [error] => Your session expired. Please login again.
    [error_params] => Array
        (
            [0] => MY_SESSION_ID
        )

    [categories] => TRY_AGAIN
    [category] => 4
    [code] => SES-0203
    [error_id] => -673980302-22682517
    [error_desc] => Your session MY_SESSION_ID expired. Please start a new browser session.
)

Login seems to be successfull, but if I would like to set the message, the session expired?? Any idea?

Trombone0904
  • 4,132
  • 8
  • 51
  • 104
  • Not sure what happens, but maybe because you use `curl_close` on each request? Which closes the connection and releases all the resources and maybe have a look [Keeping session alive with Curl and PHP](https://stackoverflow.com/questions/13020404/keeping-session-alive-with-curl-and-php) - Does Strato give you back any info eg. like a session you need to store in a Cookie? – Uwe Dec 28 '22 at 15:22
  • I removed the curl_close part - but same result. There are no information from strato :/ – Trombone0904 Dec 28 '22 at 16:58
  • Could you have a look at that answer: https://stackoverflow.com/a/1797521/5841606 – Uwe Dec 30 '22 at 03:04

0 Answers0