Link to home
Start Free TrialLog in
Avatar of mathieu_cupryk
mathieu_cuprykFlag for Canada

asked on

need to fix errors on send mail.

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
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

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)
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial