En iyi yanıtlayıcılar
Veritabanındaki Resmi Mail Body olarak gönderme

Soru
-
Arkadaşlar merhaba ;
Dizinde tutulan resmi aşağıdaki yöntemle kullanabiliyorum ama Veritabanından okuyup aynı yöntemle gönderemiyorum .
var con = new SqlConnection(@"Data Source=DBSRV;Initial Catalog=DBNAME;user=DBUSER;pwd=DBPWD");
con.Open();
var stream = new MemoryStream();
var cmd = new SqlCommand("SELECT IMAGE FROM TABLE",con);
var image = (byte[])cmd.ExecuteScalar();
stream.Write(image, 0, image.Length);
con.Close();
var bitmap = new Bitmap(stream);
var memStream = new MemoryStream();
bitmap.Save(memStream, ImageFormat.Jpeg);
var contentType = new ContentType {MediaType = MediaTypeNames.Image.Jpeg, Name = "screen"};
var mail = new MailMessage();
var smtpServer = new SmtpClient("",587);
mail.From = new MailAddress("", "");
mail.To.Add("");
mail.IsBodyHtml = true;
var oAttachment = new Attachment(memStream, contentType);
const string contentId = "companylogo";
oAttachment.ContentId = contentId;
mail.Body = "<table style='border:6px solid black ;'width='100%'><img src='cid:" + contentId +"'><b></b></font>";
smtpServer.Credentials = new NetworkCredential("", "");
smtpServer.Send(mail);
mail.Dispose();
Yanıtlar
-
Attachment olarak gondermek istiyorsaniz araya bitmap'i hic karistirmayin.
// ... var image = (byte[])cmd.ExecuteScalar(); con.Close(); MemoryStream ms = new MemoryStream(image); Attachment a = new Attachment(ms, "resim.jpg", "image/jpeg"); var mail = new MailMessage(); mail.Attachments.Add(a); // ...
body'de kullanmak icin de, yine bitmap'i hic karistirmayin ve contentId'yi attachment'dan alin:
// ... var image = (byte[])cmd.ExecuteScalar(); con.Close(); MemoryStream ms = new MemoryStream(image); Attachment a = new Attachment(ms, "resim.jpg", "image/jpeg"); var mail = new MailMessage(); mail.Attachments.Add(a); mail.Body = string.Format(@" <table style='border:6px solid black ;'width='100%'> <img src='cid:{0}'> <b></b></font>", a.ContentId ); // ...
Not: Mail.Body'nin aslinda duzgun bir HTML oldugunu var saydim.
- Düzenleyen CetinBasozEditor 22 Nisan 2016 Cuma 10:56
- Yanıt Olarak İşaretleyen Aly14 22 Nisan 2016 Cuma 11:23
Tüm Yanıtlar
-
mail.Body icinde bulunan src kısmına resmin tam yolunu yazdırmalısın.
örneğin: PATH/DB den gelen dosya adı..... http://www.domainname.com/resimadi.jpg
Birinin cevabı size yardımcı oldu ise, lütfen "Yanıt Olarak Öner" veya "Yanıt Olarak İşaretle" olarak isaretlemeyi ve Oy vermeyi unutmayınız. Burada sağlanan tüm görüşler, kişiseldir ve Microsoft'un konumunu temsil etmemektedir. Tüm bilgiler hazır olarak temin edilmektedir ve herhangi bir garanti vermemektedir.
-
-
Attachment olarak gondermek istiyorsaniz araya bitmap'i hic karistirmayin.
// ... var image = (byte[])cmd.ExecuteScalar(); con.Close(); MemoryStream ms = new MemoryStream(image); Attachment a = new Attachment(ms, "resim.jpg", "image/jpeg"); var mail = new MailMessage(); mail.Attachments.Add(a); // ...
body'de kullanmak icin de, yine bitmap'i hic karistirmayin ve contentId'yi attachment'dan alin:
// ... var image = (byte[])cmd.ExecuteScalar(); con.Close(); MemoryStream ms = new MemoryStream(image); Attachment a = new Attachment(ms, "resim.jpg", "image/jpeg"); var mail = new MailMessage(); mail.Attachments.Add(a); mail.Body = string.Format(@" <table style='border:6px solid black ;'width='100%'> <img src='cid:{0}'> <b></b></font>", a.ContentId ); // ...
Not: Mail.Body'nin aslinda duzgun bir HTML oldugunu var saydim.
- Düzenleyen CetinBasozEditor 22 Nisan 2016 Cuma 10:56
- Yanıt Olarak İşaretleyen Aly14 22 Nisan 2016 Cuma 11:23
-