Smtp sends an email with an attachment (Save the string type result as an attachment), smtpstring
This method can be directly saved as an HTML file or a text file. Other formats do not work well.
MailMessage mmsg = new MailMessage ();
Mmsg. Subject = "mail title ";
Mmsg. Body = "email content ";
Mmsg. To. Add ("accept@qq.com"); // receive mailbox
Byte [] bytes = System. Text. Encoding. Default. GetBytes
(@ "<Table> <tr> <td width = 150> 1234567891234567
</Td> <td width = 80> 12345678 </td> </tr> </table> ");
MemoryStream MS = new MemoryStream (bytes );
ContentType ct = new ContentType ();
// Attachment file type
Ct. MediaType = MediaTypeNames. Text. Html;
// Attachment name, which can be another suffix
Ct. Name = "attachment Name" + DateTime. Now. ToString () + ". html ";
Mmsg. Attachments. Add (new Attachment (MS, ct ));
// SMTP Simple Mail Protocol
System. Net. Mail. SmtpClient SC
= New System. Net. Mail. SmtpClient ();
SC. Host = "127.0.0.1"; // Host address
SC. Port = 25; // Port
// Send the email account and password
SC. Credentials =
New System. Net. NetworkCredential ("account", "password ");
// Send email
Mmsg. From = new MailAddress ("account@qq.com ");
SC. Send (mmsg );
// Release stream Resources
Ms. Close ();
Ms. Dispose ();