mathieu_cupryk
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.HtmlFile Path))
{
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.MailMessa ge' does not contain a definition for 'BodyFormat' and no extension method 'BodyFormat' accepting a first argument of type 'System.Net.Mail.MailMessa ge' could be found (are you missing a using directive or an assembly reference?) C:\Inetpub\wwwroot\EmailSu bSystemSer vice\Email SubSystemS ervice\Ema ilUtil.cs 89 25 EmailSubSystemService
Error 4 The name 'MailFormat' does not exist in the current context C:\Inetpub\wwwroot\EmailSu bSystemSer vice\Email SubSystemS ervice\Ema ilUtil.cs 89 38 EmailSubSystemService
Error 5 Property or indexer 'System.Net.Mail.MailMessa ge.To' cannot be assigned to -- it is read only C:\Inetpub\wwwroot\EmailSu bSystemSer vice\Email SubSystemS ervice\Ema ilUtil.cs 90 17 EmailSubSystemService
Error 6 Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddre ssCollecti on' C:\Inetpub\wwwroot\EmailSu bSystemSer vice\Email SubSystemS ervice\Ema ilUtil.cs 90 30 EmailSubSystemService
Error 7 Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddre ss' C:\Inetpub\wwwroot\EmailSu bSystemSer vice\Email SubSystemS ervice\Ema ilUtil.cs 91 32 EmailSubSystemService
Error 8 The name 'SmtpMail' does not exist in the current context C:\Inetpub\wwwroot\EmailSu bSystemSer vice\Email SubSystemS ervice\Ema ilUtil.cs 94 17 EmailSubSystemService
Error 9 The name 'SmtpMail' does not exist in the current context C:\Inetpub\wwwroot\EmailSu bSystemSer vice\Email SubSystemS ervice\Ema ilUtil.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\EmailSu bSystemSer vice\Email SubSystemS ervice\Ema ilUtil.cs 97 31 EmailSubSystemService
{
if (strBody == String.Empty)
{
try
{
using (StreamReader reader = new StreamReader(this.HtmlFile
{
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.MailMessa
Error 4 The name 'MailFormat' does not exist in the current context C:\Inetpub\wwwroot\EmailSu
Error 5 Property or indexer 'System.Net.Mail.MailMessa
Error 6 Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddre
Error 7 Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddre
Error 8 The name 'SmtpMail' does not exist in the current context C:\Inetpub\wwwroot\EmailSu
Error 9 The name 'SmtpMail' does not exist in the current context C:\Inetpub\wwwroot\EmailSu
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\EmailSu
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
email.From = New System.Net.Mail.MailAddres
email.To.Add(New System.Net.Mail.MailAddres
email.CC.Add(New System.Net.Mail.MailAddres
email.IsBodyHtml = True
Dim smtp As System.Net.Mail.SmtpClient
smtp.Send(email)