I am receiving emails through hmailserver
and sending those emails as .eml file as an attachment of another report email.
I am having issues in reading and sending those emails as an attachment.
This is what I am doing.
public void addAttachment(string pathname, bool retry)
{
string attachmentname = "";
do
{
try
{
attachmentname = Path.GetFileNameWithoutExtension(pathname);
Stream file = new MemoryStream(File.ReadAllBytes(pathname));
Log.WriteMessage("Size" + file.Length);
dtstreamAttach.Add(attachmentname+".eml", file);
retry = false;
}
catch (ArgumentException e)
{
string strCurrentTs = DateTime.Now.ToString(strDateFormat);
attachmentname = attachmentname + "-" + strCurrentTs+".eml";
}
} while (retry);
}
Then,
MailMessage message = new MailMessage();
.
.
message.Attachments.Add(new Attachment(kvp.Value, kvp.Key)); // I have an attachment dictionary
string contenttype = GetMimeType(".eml");
ContentType cnttype = new ContentType(contenttype);
message.Attachments[0].ContentType = cnttype;
as you see i print the Stream size - which prints out as something like 4790Bytes (4KB) But when i receive the email, i only get an eml file with size 1KB and the eml file is empty.
I have checked the file paths and also made sure that the email is there until my report mail is sent out.
I have also verified content type is message/rfc822
.
Everything seems to check out. Not sure what the issue is.