asp .net 发邮件(带附件)测试可用

  string file = @"c:\ok.xls";
      
        string to = "***@sina.com";
        string from = "***@163.com";
        string subject = "dfsdfsafdsfasfds.";
        string body = @"Using this new feature, you can send an e-mail message from an application very easily.";
        System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to, subject, body);
        message.From = new MailAddress("***@163.com", "逄瑞锋");

        Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);      
        // Add the file attachment to this e-mail message.
        message.Attachments.Add(data);
        SmtpClient client = new SmtpClient("smtp.163.com", 25);
        // Credentials are necessary if the server requires the client
        // to authenticate before it will send e-mail on the client's behalf.
        client.Credentials = new NetworkCredential("username", "password");

        client.Send(message);
        data.Dispose();

原文地址:https://www.cnblogs.com/ma/p/505334.html