need to fix errors on send mail.

Posted on 2009-07-08
Last Modified: 2012-05-07
public string SendEmail(string name, string emailAddress)
            if (strBody == String.Empty)
                    using (StreamReader reader = new StreamReader(this.HtmlFilePath))
                        strBody = reader.ReadToEnd();
                catch (Exception ex)
                    throw new Exception("error reading HTML File" + ex.Message);
                MailMessage Message = new MailMessage();
                Message.BodyFormat = MailFormat.Html;
                Message.To = emailAddress;
                Message.From = this.FromEmail;
                Message.Subject = this.Subject;
                Message.Body = strBody;
                SmtpMail.SmtpServer = this.SmtpServer;
            catch (System.Web.HttpException ehttp)
                throw new Exception("Send error" + ehttp.Message);
            return "sent" + name;

Error      3      'System.Net.Mail.MailMessage' does not contain a definition for 'BodyFormat' and no extension method 'BodyFormat' accepting a first argument of type 'System.Net.Mail.MailMessage' could be found (are you missing a using directive or an assembly reference?)      C:\Inetpub\wwwroot\EmailSubSystemService\EmailSubSystemService\EmailUtil.cs      89      25      EmailSubSystemService
Error      4      The name 'MailFormat' does not exist in the current context      C:\Inetpub\wwwroot\EmailSubSystemService\EmailSubSystemService\EmailUtil.cs      89      38      EmailSubSystemService
Error      5      Property or indexer 'System.Net.Mail.MailMessage.To' cannot be assigned to -- it is read only      C:\Inetpub\wwwroot\EmailSubSystemService\EmailSubSystemService\EmailUtil.cs      90      17      EmailSubSystemService
Error      6      Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddressCollection'      C:\Inetpub\wwwroot\EmailSubSystemService\EmailSubSystemService\EmailUtil.cs      90      30      EmailSubSystemService
Error      7      Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress'      C:\Inetpub\wwwroot\EmailSubSystemService\EmailSubSystemService\EmailUtil.cs      91      32      EmailSubSystemService
Error      8      The name 'SmtpMail' does not exist in the current context      C:\Inetpub\wwwroot\EmailSubSystemService\EmailSubSystemService\EmailUtil.cs      94      17      EmailSubSystemService
Error      9      The name 'SmtpMail' does not exist in the current context      C:\Inetpub\wwwroot\EmailSubSystemService\EmailSubSystemService\EmailUtil.cs      95      17      EmailSubSystemService
Error      10      The type or namespace name 'HttpException' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)      C:\Inetpub\wwwroot\EmailSubSystemService\EmailSubSystemService\EmailUtil.cs      97      31      EmailSubSystemService
Question by:mathieu_cupryk
  • 2
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 24807486
you're confusing 1.1 with 2.0:

 email.From = New System.Net.Mail.MailAddress("FROM_ADDR")
            email.To.Add(New System.Net.Mail.MailAddress(ConfigurationManager.AppSettings("EmailNotificationIT").ToString()))
            email.CC.Add(New System.Net.Mail.MailAddress(Session("EmailAddr")))
            email.IsBodyHtml = True

            Dim smtp As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings("MailServer").ToString())
LVL 40

Accepted Solution

Kyle Abrahams earned 500 total points
ID: 24807525
                Message.From =New System.Net.Mail.MailAddress(this.FromEmail);
                Message.Subject = this.Subject;
                Message.Body = strBody;
               Dim smtp As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient(this.SmtpServer);


Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In a recent question ( here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question