473,379 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

C# sent Email Visualization Problem

Hello.. I'm using the C# class System.Net.Mail.MailMessagein order to send Emails in HTML Format. The HTML body comes from a Crystal Report converted to HTML Format 40 through the Crystal Class from Visual Studio .NET

The problem is that the e-mail looks just fine in e-mail clients such as Microsoft Outlook, howeverer, if i try to forward the e-mail it looks all bad, all aligned to the left and it looses all format. The same thing happens when i send the email to servers such as G-mail or hotmail.

The e-mail has embedded images, and this is part of the code used to send the e-mails

Expand|Select|Wrap|Line Numbers
  1.                 System.Net.Mail.MailMessage mensajeEmail = new System.Net.Mail.MailMessage();
  2.                 System.Net.NetworkCredential cred = new System.Net.NetworkCredential(_user, _password);
  3. //                mensajeEmail.IsBodyHtml = true; // Aceptamos HTML
  4.                 foreach(string _destinatario in _para)
  5.                 {
  6.                     if (_destinatario != null)
  7.                     {
  8.                         mensajeEmail.To.Add(_destinatario);
  9.                     }
  10.                 }
  11.                 if (_cc != null)
  12.                 {
  13.                     foreach (string _copia in _cc)
  14.                     {
  15.                         if (_copia != null)
  16.                         {
  17.                             mensajeEmail.CC.Add(_copia);
  18.                         }
  19.                     }
  20.                 }
  21.                 if (_bcc != null)
  22.                 {
  23.                     foreach (string _copiaOculta in _bcc)
  24.                     {
  25.                         if (_copiaOculta != null)
  26.                         {
  27.                             mensajeEmail.Bcc.Add(_copiaOculta);
  28.                         }
  29.                     }
  30.                 }
  31.  
  32.                 mensajeEmail.Subject = _subject;
  33.                 mensajeEmail.From = new System.Net.Mail.MailAddress(_fromMail, _from);
  34.                 string _bodyMessage = _mensaje;
  35.                 int _secImagen = 0;
  36. //se cambia cada coincidencia de "images/nombre de la imagen" por un consecutivo cid:imagenN para luego asociarlas.
  37.                 foreach (string _imagenes in images)
  38.                 {
  39.                     string _imagen = _imagenes.Replace(_filePath + "\\", "");
  40.                     _bodyMessage = _bodyMessage.Replace("images/" + _imagen, "cid:imagen" + _secImagen.ToString());
  41.                     _secImagen++;
  42.                 }
  43.  
  44.                 System.Net.Mail.AlternateView html = 
  45.                     System.Net.Mail.AlternateView.CreateAlternateViewFromString(_bodyMessage, System.Text.Encoding.UTF8 , "text/html");
  46.  
  47.  
  48. //se agrega cada imagen al mensaje como un recurso enlazado
  49.                 _secImagen = 0;
  50.                 foreach (string _imagenes in images)
  51.                 {
  52.                     System.Net.Mail.LinkedResource imagen = new System.Net.Mail.LinkedResource(_imagenes);
  53.                     imagen.ContentId = "imagen" + _secImagen.ToString();
  54.                     _secImagen++;
  55.                     html.LinkedResources.Add(imagen);
  56.                 }
  57.                 mensajeEmail.AlternateViews.Add(html);
  58.                 mensajeEmail.IsBodyHtml = true;
  59.  
  60. //                mensajeEmail.Body = _mensaje;
  61.                 System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(_serverName); //seleccionamos nuestro servidor smtp
  62.                 smtp.UseDefaultCredentials = false;
  63. //                smtp.EnableSsl = true;
  64.                 smtp.Credentials = cred; //asignamos la credencial
  65. //                mensajeEmail.Attachments.Add(archivoAnexo); //se agregan los archivos anexos
  66.                 smtp.Send(mensajeEmail); // enviamos
  67.             }
  68.             catch(Exception ex)
  69.             {
  70.                 System.Console.WriteLine(ex.Message.ToString() + " -***- " + ex.Source.ToString()
  71.                     + " -***- " + ex.Source.ToString());
  72. //                System.Console.ReadLine();
  73.                 return false;
  74.             }
  75.             return true;
  76.  
BTW I'm using embedded images in this e-mail.

Those anyone knows how to make the e-mails look fine on any client? I'm really stuck and desperate in this... I have tried different types of encodings and nothing seems to work.

Thanks

Oliver
Feb 9 '07 #1
1 2333
kenobewan
4,871 Expert 4TB
Email clients are like browsers, you can't absolutely control what happens after you serve your code to the client. You can't even ensure that everyone accepts html emails. The simpler the code the more likely it will look the same in the widest range of email clients. Suggest you choose the cleanest format and test in a range of clients. Probably easiest to work backwards once you have the email you want than adjust the code...
Feb 11 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Kelvin Klein | last post by:
Is there a visualization tool for C program out there? Is there a visualization tool for the language of one of the crossposted newsgroup out there? I am a refuge from comp.lang.c, kicked out...
2
by: Umesh Persad | last post by:
Hi All, I am looking for a platform to rapidly develop software for Information Visualization. Since I am working in an academic environment, I want to be able to develop applications quickly...
1
by: Noname | last post by:
Hi All I am working for a EE Department. We are in the process of developing some application that requires 3D visualization and other display routines. Can anyone clarify that if thats possible....
1
by: hailconan | last post by:
Hi everyones, I would like to display a stream of data on visualization view like FFT. I have read the data from an array (voice, file, ...) but I could not find a component in ActiveX helps me...
0
by: David T | last post by:
Has anyone run across this error? When calling any of several visualization routines from FiPy, Python quits with a Bus Error I'm using MacOS X Tiger 10.4.3, and I've tried several builds...
34
by: antonyliu2002 | last post by:
I've set up the virtual smtp server on my IIS 5.1 like so: 1. Assign IP address to "All Unassigned", and listen to port 25. 2. Access Connection granted to "127.0.0.1". 3. Relay only allow...
11
by: Fie Pye | last post by:
Hallo I would like to have a high class open source tools for scientific computing and powerful 2D and 3D data visualisation. Therefore I chosepython, numpy and scipy as a base. Now I am in...
9
by: Xah Lee | last post by:
REQUIREMENTS FOR A VISUALIZATION SOFTWARE SYSTEM FOR 2010 Xah Lee, 2007-03-16 In this essay, i give a list of requirements that i think is necessary for a software system for creating...
0
by: JDeats | last post by:
Looking to build an desktop application for a client using WPF/ Silverlight 2.0 or Adobe Flex 2.0 and because of my ability to use C# and the integration requirements, the WPF solution would be the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.