MailKit을 사용하여 memoryStream에서 첨부 파일이있는 이메일을 보내는 방법은 무엇입니까? 현재 일반 SMTP를 사용하여 전송하고 아래 코드를 사용하여 파일을 첨부하고 있지만 MailKit 패키지를 사용하여 전송하는 적절한 예제를 찾을 수 없습니다. 이 두 문서를 살펴 보았지만 적절한 해결책을 찾을 수 없습니다. http://www.mimekit.net/docs/html/M_MimeKit_AttachmentCollection_Add_6.htm
using System.Net.Mail;
MemoryStream memoryStream = new MemoryStream(bytes);
message.Attachments.Add(new Attachment(memoryStream, "Receipt.pdf", MediaTypeNames.Application.Pdf));
이것은 내 MailKit 이메일 코드입니다.
#region MailKit
string fromEmail = GlobalVariable.FromEmail;
string fromEmailPwd = "";//add sender password
var email = new MimeKit.MimeMessage();
email.From.Add(new MimeKit.MailboxAddress("Sender", fromEmail));
email.To.Add(new MimeKit.MailboxAddress("receiver", "[email protected]"));
var emailBody = new MimeKit.BodyBuilder
{
HtmlBody = htmlString
};
email.Subject = "test Booking";
email.Body = emailBody.ToMessageBody();
//bytes is parameter.
//MemoryStream memoryStream = new MemoryStream(bytes);
//message.Attachments.Add(new Attachment(memoryStream, "Receipt.pdf", MediaTypeNames.Application.Pdf));
using (var smtp = new MailKit.Net.Smtp.SmtpClient())
{
smtp.Connect("smtp.gmail.com", 465, true);
smtp.Authenticate(fromEmail, fromEmailPwd);
smtp.Send(email);
smtp.Disconnect(true);
}
#endregion
MimeKit의 BodyBuilder를 사용하여 메시지 본문을 작성하려면 다음과 같이 할 수 있습니다.
var emailBody = new MimeKit.BodyBuilder
{
HtmlBody = htmlString
};
emailBody.Attachments.Add ("Receipt.pdf", bytes);
// If you find that MimeKit does not properly auto-detect the mime-type based on the
// filename, you can specify a mime-type like this:
//emailBody.Attachments.Add ("Receipt.pdf", bytes, ContentType.Parse (MediaTypeNames.Application.Pdf));
message.Body = emailBody.ToMessageBody ();
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다