c#下发送邮件代码

c#下发送邮件代码
public   class  SendMail
    
{
        System.Net.Mail.SmtpClient client 
= new SmtpClient();
        System.Net.Mail.MailMessage message 
= null;

        
public SendMail()
        
{
            client.Host 
= "smtp.163.com";
            client.UseDefaultCredentials 
= false;
            client.Credentials 
= new System.Net.NetworkCredential("你的邮箱""密码");

            client.DeliveryMethod 
= SmtpDeliveryMethod.Network;

            message 
= new MailMessage("你的邮箱""对方邮箱");
        }


        
public void DoSend(string subject, string body)
        
{
            message.Subject 
= subject;
            message.Body 
= body;
            message.BodyEncoding 
= System.Text.Encoding.UTF8;
            message.IsBodyHtml 
= true;
            
try
            
{
                client.Send(message);
            }

            
catch
            
{
            }

        }

    }

你可能感兴趣的:(c#下发送邮件代码)