The safest way to get mail postmarked by midnight is to deliver it in person to a post office before the last mail collection of the day and before the end of that post office's operating hours. Some post offices have automatic postal centers that also deliver the desired postmark.
Many people seeking postmarks by midnight on a given day are trying to mail their tax returns before the IRS midnight deadline. Fewer post offices stay open till midnight on tax due dates than did so in the past because so many people now file taxes electronically. Applying a metered time stamp to get a postmark before midnight and then delivering the letter to a post office at a later date is likely to result in the mail being rejected.