第一種發(fā)送方式
```
public bool SendEmail(string UserEmail, string randcode)
? ? ? ? {
? ? ? ? ? ? string SendEmail = "郵箱賬號";
? ? ? ? ? ? string SendPwd = "郵箱密碼/驗證方式,具體查看下圖";
? ? ? ? ? ? SmtpClient _smtpClient = new SmtpClient();
? ? ? ? ? ? _smtpClient.EnableSsl = true;
? ? ? ? ? ? _smtpClient.UseDefaultCredentials = false;
? ? ? ? ? ? _smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
? ? ? ? ? ? _smtpClient.Host = "smtp.qq.com";
? ? ? ? ? ? _smtpClient.Port = 587;
? ? ? ? ? ? _smtpClient.Credentials = new System.Net.NetworkCredential(SendEmail, SendPwd);
? ? ? ? ? ? //密碼不是QQ密碼,是qq賬戶設(shè)置里面的POP3/SMTP服務(wù)生成的key
? ? ? ? ? ? MailMessage _mailMessage = new MailMessage(SendEmail, UserEmail);
? ? ? ? ? ? _mailMessage.Subject = "";//主題?
? ? ? ? ? ? _mailMessage.Body = "";//郵件正文
? ? ? ? ? ? _mailMessage.BodyEncoding = Encoding.Default;//正文編碼?
? ? ? ? ? ? _mailMessage.IsBodyHtml = true;//設(shè)置為HTML格式?
? ? ? ? ? ? _mailMessage.Priority = MailPriority.High;//優(yōu)先級?
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? _smtpClient.Send(_mailMessage);
? ? ? ? ? ? ? ? Console.WriteLine("發(fā)送成功");
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception e)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.WriteLine("發(fā)送失敗");
? ? ? ? ? ? ? ? throw e;
? ? ? ? ? ? }
? ? ? ? }
```

第二種方式
需要引用CDO組件發(fā)送,Interop.CDO和Interop.ADODB
但是記住 CDO引用嵌入式必須修改為false否則會提示錯誤。
-----------------------------------------------------------------------------------------
public bool SendEmail(string UserEmail, string randcode)
? ? ? ? {
? ? ? ? ? ? bool result = false;
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Message oMsg = new Message();
? ? ? ? ? ? ? ? //Configuration conf = new ConfigurationClass();
? ? ? ? ? ? ? ? oMsg.Configuration.Fields[CdoConfiguration.cdoSendUsingMethod].Value = CdoSendUsing.cdoSendUsingPort;
? ? ? ? ? ? ? ? oMsg.Configuration.Fields[CdoConfiguration.cdoSMTPAuthenticate].Value = CdoProtocolsAuthentication.cdoBasic;
? ? ? ? ? ? ? ? oMsg.Configuration.Fields[CdoConfiguration.cdoSMTPUseSSL].Value = true;
? ? ? ? ? ? ? ? //QQ企業(yè)郵箱
? ? ? ? ? ? ? ? /*
? ? ? ? ? ? ? ? oMsg.Configuration.Fields[CdoConfiguration.cdoSMTPServer].Value = "smtp.exmail.qq.com";//必填,而且要真實可用?
? ? ? ? ? ? ? ? oMsg.Configuration.Fields[CdoConfiguration.cdoSMTPServerPort].Value = 465;//郵箱端口
? ? ? ? ? ? ? ? */
? ? ? ? ? ? ? ? //網(wǎng)易郵箱
? ? ? ? ? ? ? ? oMsg.Configuration.Fields[CdoConfiguration.cdoSMTPServer].Value = "smtphm.qiye.163.com";//必填,而且要真實可用?
? ? ? ? ? ? ? ? oMsg.Configuration.Fields[CdoConfiguration.cdoSMTPServerPort].Value = 994;//郵箱端口
? ? ? ? ? ? ? ? string SendEmail = "郵箱賬號";
? ? ? ? ? ? ? ? string SendPwd = "郵箱密碼";
? ? ? ? ? ? ? ? oMsg.Configuration.Fields[CdoConfiguration.cdoSendEmailAddress].Value = SendEmail;//發(fā)送者郵箱
? ? ? ? ? ? ? ? oMsg.Configuration.Fields[CdoConfiguration.cdoSendUserName].Value = SendEmail;//郵箱發(fā)送者名稱?
? ? ? ? ? ? ? ? oMsg.Configuration.Fields[CdoConfiguration.cdoSendPassword].Value = SendPwd;? //郵箱發(fā)送者密碼,必須真實
? ? ? ? ? ? ? ? oMsg.Configuration.Fields.Update();
? ? ? ? ? ? ? ? //oMsg.Configuration = conf;
? ? ? ? ? ? ? ? oMsg.TextBody = "";//郵件正文
? ? ? ? ? ? ? ? oMsg.Subject = "";//主題? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? oMsg.From = SendEmail;//發(fā)送者
? ? ? ? ? ? ? ? oMsg.To = UserEmail;//接收者
? ? ? ? ? ? ? ? try
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? oMsg.Send();//發(fā)送
? ? ? ? ? ? ? ? ? ? result = true;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? catch
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? result = false;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? catch
? ? ? ? ? ? {
? ? ? ? ? ? ? ? result = false;
? ? ? ? ? ? }
? ? ? ? ? ? return result;
? ? ? ? }