Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...