Solved

need to fix errors on send mail.

Posted on 2009-07-08
2
1,704 Views
Last Modified: 2012-05-07
public string SendEmail(string name, string emailAddress)
        {
            if (strBody == String.Empty)
            {
                try
                {
                    using (StreamReader reader = new StreamReader(this.HtmlFilePath))
                    {
                        strBody = reader.ReadToEnd();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("error reading HTML File" + ex.Message);
                }
            }
            try
            {
                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;
                SmtpMail.Send(Message);
            }
            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
0
Comment
Question by:mathieu_cupryk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
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())
            smtp.Send(email)
0
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 24807525
  Message.isBodyHtml=true;
                Message.To.Add(emailAddress);
                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);
                smpt.Send(Message);


0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp Google Map 2 93
asp.net mvc , views, hidden values ? 2 27
Can Angular be used with classic asp.net? 3 45
Web Site Administration Tool - Security Questions 2 39
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
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…

751 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