error in code

srinivaskr

Newcomer
Joined
Sep 27, 2009
Messages
7
Code:
using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.Mail;
using System.Net.Mail;

[WebService(Namespace = "http://MailServiceSample/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class SentEmail : System.Web.Services.WebService
    {
        [WebMethod]
        public string Sending_Email(string strEmailAddrFrom,string[] strEmailAddrTo, int intTotalEmailTo, string strAttachement)
        {
            EmailAlert NewMail=new EmailAlert();
            return NewMail.EmailSent(strEmailAddrFrom,strEmailAddrTo, intTotalEmailTo, strAttachement);
        }
public string EmailSent(string strEmailAddrFrom, 
	string [] strEmailAddrTo, int intTotalEmailTo, string strAttachement)
        {
            string strSent= " ";
            try
            {
                System.Net.Mail.MailMessage myMailMessage = new System.Net.Mail.MailMessage();
                myMailMessage.From = new MailAddress(strEmailAddrFrom, "Admin");
                myMailMessage.Subject = "Error On Optimizer Program";
                myMailMessage.Body = "Error On Optimizer Program.Please check the detail from the attachment";
                myMailMessage.IsBodyHtml = true;
                myMailMessage.Priority = System.Net.Mail.MailPriority.High;
                for (int NumberOfEmails = 0; NumberOfEmails < intTotalEmailTo; NumberOfEmails++)
                {
                    myMailMessage.To.Add(new MailAddress(strEmailAddrTo[NumberOfEmails]));
                }
                if (strAttachement != "" || strAttachement != null)
                {
                    Attachment att = new Attachment(strAttachement);
                    myMailMessage.Attachments.Add(att);
                }
                SmtpClient myMailClient = new SmtpClient();
                myMailClient.Host = "www.mymailhost.net";
                myMailClient.Port = 25;
                myMailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                object userState = myMailMessage;
                try
                {
                    Console.WriteLine("Mail Sending In progress");
                    myMailClient.Send(myMailMessage);
                }
                catch (System.Net.Mail.SmtpException ex)
                {
                    Console.WriteLine(ex.Message, "Send Mail Error");
                    strSent = strSent + ex.Message;
                }
                myMailMessage.Dispose();
                strSent = "Mail Sent !!";
            }
            catch (System.Net.Mail.SmtpException exSmtp)
            {
                Console.WriteLine("Exception occurred:" + 
			exSmtp.Message, "SMTP Exception Error");
                strSent = strSent + "Exception occurred:" + exSmtp.Message;
            }
            catch (System.Exception exGen)
            {
                Console.WriteLine("Exception occurred:" + 
			exGen.Message, "General Exception Error");
                strSent = strSent + "Exception occurred:" + exGen.Message;
            }
            return strSent;
        } 
}

the above code is returning error in line EmailAlert NewMail=new EmailAlert(); it says missing directive or assembly reference for EmailAlert. please help me resolve this problem.
 
Back
Top