Dear All;
I have an List
realimages ;
and I want to send email by the images I have ..
I have wrote a code but it I can attach a file , but I cannot stream the image into bytes then attach it by the mail..
here is my function
public void button3_Click(object sender, EventArgs e)
{
MailMessage message = new MailMessage(
"from@gmail.com",
"to@hotmail.com",
"Quarterly data report.",
"See the attached spreadsheet.");
MemoryStream stream = new MemoryStream();
realimage[0].Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
stream.ToArray();
Attachment data = null;
MessageBox.Show(stream.Length.ToString());
byte[] contentAsBytes;
contentAsBytes = stream.ToArray();
stream.Write(contentAsBytes, 0, contentAsBytes.Length);
stream.Seek(0, SeekOrigin.Begin);
ContentType contentType = new ContentType();
contentType.MediaType = MediaTypeNames.Application.Octet;
contentType.Name = "test";
ContentType contenttype = new ContentType();
contenttype.MediaType = MediaTypeNames.Text.Html;
data = new Attachment(stream, contenttype);
message.Attachments.Add(data);
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Credentials = CredentialCache.DefaultNetworkCredentials;
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in CreateMessageWithAttachment(): {0}",
ex.ToString());
}
ContentDisposition cd = data.ContentDisposition;
Console.WriteLine("Content disposition");
Console.WriteLine(cd.ToString());
Console.WriteLine("File {0}", cd.FileName);
Console.WriteLine("Size {0}", cd.Size);
Console.WriteLine("Creation {0}", cd.CreationDate);
Console.WriteLine("Modification {0}", cd.ModificationDate);
Console.WriteLine("Read {0}", cd.ReadDate);
Console.WriteLine("Inline {0}", cd.Inline);
Console.WriteLine("Parameters: {0}", cd.Parameters.Count);
foreach (DictionaryEntry d in cd.Parameters)
{
Console.WriteLine("{0} = {1}", d.Key, d.Value);
}
data.Dispose();
}
How can i send an email by buffering the images without a file path and attach in the mail..
regards...