Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1769
  • Last Modified:

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
0
mathieu_cupryk
Asked:
mathieu_cupryk
  • 2
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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
 
Kyle AbrahamsSenior .Net DeveloperCommented:
  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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now