The spam filtering system is used to identify which emails in the received emails are completely meaningless to the recipient and perform operations such as interception and deletion. Nowadays, with the rapid development of the Internet, while e-mail provides convenience for people, spam also comes along with it, which brings many troubles to users. According to statistics, 80% of the emails in the world are spam, and e-spam is really annoying. Therefore, how to solve the problem of filtering emails has important practical significance. Spam filtering using Bayesian theory is a statistical technique applied to email filtering. It essentially uses Bayesian classification to discriminate the attributes of emails, including spam and non-spam. Bayesian-based spam filtering is a very effective technique that can modify the model to meet the needs of specific users and give a lower spam detection rate that is acceptable to users. In this experiment, we use Naive Bayes for experiments, and we use Unigram and bigram methods to preprocess the data, respectively. Finally, it is concluded that the data processing accuracy of unigram and bigram is greater than 0.75, and bigram performs better in four different evaluation indicators.