The rules for ti and di, in other words with i are very simple. The rules for te and de, with an e are more tricky. The combination of ti or di is always, wheter at the beginning of word, in midst of a word or at the end of a word is pronounced /tsh/ or /dshi/. In this pseudo phonetic transcription t means unvoiced and d means voiced. Concerning the difference between voiced / unvoiced see 18.104.22.168. In the pseudo phonetic transcription /tsh/ stands for unvoiced, because the t is always unvoiced, and /dsh/ for voiced, because the d is always voiced. This is actually the difference between t and d. This pseudo phonetic transcription is often used in grammar books.
Concerning te and de a distinction is to be made. If the words ends in e and the stress is not on the last syllable, it is pronounced i. In this case we have the same situation as if it were ti / di and the pronounciation is the same as in the case of ti / di. At the beginning of a word or in midst of the word however the e is pronounced as an e, similar to the e in ever, in any case not as an i, and therefore te / de is pronounced /te/ and /de/.
ti / di always pronounced /tshi/ [tʃi] or /dshi/ [dʒi]
divulgar (to diffuse)
te is pronounced /tshi/ [tʃi] and de is pronounced /dschi/ [dʒi] in stressed final syllable
de (of / from )
Note: In words like até (until) the last syllable is stressed and therefore the e is pronounced as an e. Furthermore the rule that the e is pronounced as an i in unstressed last syllable is only valid for Brasilian Portuguese.