Encrypting mail message with C++ API

I am trying to send an encrypted/signed mail message with the C++ API. But when calling mail.Encrypt() or mail.Sign() I get the following error message: “Unable to perform operation due to unopened database”. What database is needed to be opened here?

Actually it seems that the subsequent call to mail.Save() is producing this error. But I don’t know how to fix this problem. The API help is not really helpful here.