MailKit 라이브러리를 사용하여 잘 작동하는 전자 메일을 처리하고 있습니다. 그러나 전자 메일을 구성 파일로 분할하려고합니다. a) 기본 전자 메일 (첨부 파일 없음) b) 개별 첨부 파일, 파일 시스템에 저장합니다.MailKit/MimeKit을 사용하여 전자 메일에서 첨부 파일 제거하기
첨부 파일을 개별적으로 저장할 수는 있지만 전자 메일 본문 코드에서 첨부 파일을 제거 할 수 없습니다. 나는. 주요 이메일과 함께 저장되므로 데이터가 복제됩니다. :/
나는 시도했다 :
foreach (MimePart part in inMessage.BodyParts)
{
if (part.IsAttachment)
{
// Remove MimePart < This function isn't available on the collection.
}
}
도 시도 해 봤나 : 사람이 도움을 줄 수있는 경우
var builder = new BodyBuilder();
foreach (MimePart part in inMessage.BodyParts)
{
if (!part.IsAttachment)
{
// Add MimeParts to collection < This function isn't available on the collection.
}
}
outMessage.Body = builder.ToMessageBody();
, 나는 많은 거라고를 주셔서 감사합니다.
솔루션 참고 구현 :
private List<string> GetAttachments(string outDirPath)
{
MimeMessage message = (Master as fsEmail).GetMimeMessage();
List<string> list = new List<string>();
foreach (MimePart attachment in message.Attachments)
{
using (var cancel = new System.Threading.CancellationTokenSource())
{
string filePath = outDirPath + Guid.NewGuid().ToString() + Path.GetExtension(attachment.FileName);
using (var stream = File.Create(filePath))
{
attachment.ContentObject.DecodeTo(stream, cancel.Token);
list.Add(filePath);
}
}
}
return list;
}
이 유용 http://www.limilabs.com/blog/download-email-attachments-net –
감사가 될 수 있지만,이 링크를 기반으로 이렇게하려면, 당신의 코드는 다음과 같을 것 Mail.dll 그리고 나는 이상적으로 MailKit을 고수하고 싶다. – FrugalTPH
FWIW, 디스크에 첨부 파일 저장을 취소 할 계획이 아니라면 취소 토큰을 만들 필요가 없습니다. CancellationToken.None을 사용하거나 취소 토큰을 전혀 전달하지 않을 수 있습니다. – jstedfast