I added a pdf file to my MailMassege and After sending it, I got the Email with pdf file that cannot be opened and it's size is much smaller than the original file, what am I missing ?? this is my code :
public void createMailWithBytesAttachment(string to,string from, string pdfUrl, string body,string FileName,string subject) {
MailMessage oMail = new MailMessage();
using (WebClient client = new WebClient())
{
var bytes = client.DownloadData(pdfUrl);
string base64String = Convert.ToBase64String(bytes);
}
var fileName = FileName;
var myByteArray = System.Text.Encoding.UTF8.GetBytes(pdfUrl);
MemoryStream strm = new MemoryStream(myByteArray);
Attachment data = new Attachment(strm, fileName);
ContentDisposition disposition = data.ContentDisposition;
//data.ContentId = fileName;
//data.ContentDisposition.Inline = true;
oMail.Attachments.Add(data);
oMail.From = new MailAddress(from);
oMail.To.Add(to);
oMail.Subject = subject;
oMail.Body = body;
SmtpClient oSmtp = new SmtpClient();
SmtpClient oServer = new SmtpClient("xxx.xxx.xxx.xxx");
oServer.Port = yy;
oServer.EnableSsl = false;
try
{
oServer.Send(oMail);
}