Solved

need to fix errors on send mail.

Posted on 2009-07-08
2
1,648 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
  • 2
2 Comments
 
LVL 39

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 39

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now