Stored procedure sp_send_dbmail fails when the @query parameter is specified and the same batch previously invoked OLE automation procs. The error messages are:
Msg 22050, Level 16, State 1, Line 0
Error formatting query, probably invalid parameters
Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 478
Query execution failed: Error Intiailizing COM . CoInitialize failed with Hresult: 0x80010106
Note that the repro script executes as expected if a GO batch terminator is specified after the sp_OADestroy. However, this workaround is not an option in stored procedure code.
Dan Guzman, SQL Server MVP