示例#1
0
        public void SendEmail()
        {
            //create the mail message
            MailMessage mail = new MailMessage();

            //set the addresses
            mail.From = new MailAddress(From);
            mail.To.Add(To);

            //set the content
            mail.Subject = "Sent with KNDLComic";
            mail.Body    = "";

            //create the attachment from a stream. Be sure to name the data with a file and
            //media type that is respective of the data
            System.Net.Mime.ContentType ct     = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Application.Pdf);
            System.Net.Mail.Attachment  attach = new System.Net.Mail.Attachment(Attachment, ct);
            attach.ContentDisposition.FileName = AttachmentFileName + ".pdf";
            mail.Attachments.Add(attach);

            //send the message
            SmtpClient SmtpServer = new SmtpClient("smtp.live.com", 587); //hotmail smtp, adapt to yours

            SmtpServer.Port = 587;
            SmtpServer.UseDefaultCredentials = false;
            SmtpServer.Credentials           = new System.Net.NetworkCredential(From, "PasswordHere");
            SmtpServer.EnableSsl             = true;
            SmtpServer.Send(mail);
            Attachment.Close();
        }