sending mails through webservices
-
Hi, I am sending emails through webservices, I am calling the webservice from my website and passing all the arguments to it ,until now no problem. But now I want the webservice to inform the user if an error or exception occurs is there a way by which I can do so? Any help shall be appreciated
Thanks Shankbond
-
Hi, I am sending emails through webservices, I am calling the webservice from my website and passing all the arguments to it ,until now no problem. But now I want the webservice to inform the user if an error or exception occurs is there a way by which I can do so? Any help shall be appreciated
Thanks Shankbond
-
Return the exception in the form of String format...!
[WebMethod]
Public string SendMail()
{
try
{
return "mail sent";
}
Catch(Exception ie)
{
return ie.Message;
}
}LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.
Hi, Your method is very simple but when I tried to send the mail using webservice I tried like: testingservice service=new testingservice; string message=service.send mail(,,,.....parameters); where as I have declared the web service as [WebMethod] Public string SendMail(,,,.....parameters) { try { return "mail sent"; } Catch(Exception ie) { return ie.Message; } } I get an error and the application fails to rebuild Cannot implicitly convert type 'System.IAsyncResult' to 'string' Please reply
Thanks Shankbond
-
Hi, Your method is very simple but when I tried to send the mail using webservice I tried like: testingservice service=new testingservice; string message=service.send mail(,,,.....parameters); where as I have declared the web service as [WebMethod] Public string SendMail(,,,.....parameters) { try { return "mail sent"; } Catch(Exception ie) { return ie.Message; } } I get an error and the application fails to rebuild Cannot implicitly convert type 'System.IAsyncResult' to 'string' Please reply
Thanks Shankbond
Hi, You misunderstood i think..! You have to write a web method for sending mail
[WebMethod]
Public string SendMail(,,,.....parameters)
{
try
{
//You Have to Write the logic for sending mail..!
return "mail sent";
}
Catch(Exception ie)
{
return ie.Message;
}
}if you wrote the logic for sending the mail show me the code..!
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.
-
Hi, You misunderstood i think..! You have to write a web method for sending mail
[WebMethod]
Public string SendMail(,,,.....parameters)
{
try
{
//You Have to Write the logic for sending mail..!
return "mail sent";
}
Catch(Exception ie)
{
return ie.Message;
}
}if you wrote the logic for sending the mail show me the code..!
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.
Hi, here is the code:
protected void Button4_Click(object sender, EventArgs e)
{
testingservice service = new testingservice();
AsyncCallback callback = new AsyncCallback(hello);
service.BeginSendMailGmail1(TextBoxto.Text.ToString(), TextBoxcc.Text.ToString(), TextBoxbcc.Text.ToString(), TextBoxbody.Text.ToString(), TextBoxsubject.Text.ToString(), TextBoxusername.Text.ToString(), TextBoxpassword.Text.ToString(), TextBoxserver.Text.ToString(), TextBoxport.Text.ToString(), TextBoxdisplayname.Text.ToString(),callback,sender);
Response.Redirect("default4.aspx");
}here is the other method but it will always be completed =true
void hello(IAsyncResult result)
{
if (!result.IsCompleted)
{
Response.Write("failed");
}
}the code for webservice:
[WebMethod]
public string SendMailGmail1(string To, string Cc, string Bcc, string body,string subject, string user\_name, string password, string server\_name, string portnumber, string display\_name) { SmtpClient client = new SmtpClient(); MailMessage message = new MailMessage(); client.Port = Convert.ToInt32(portnumber); client.Host = server\_name; client.UseDefaultCredentials = true; client.Credentials = new System.Net.NetworkCredential(user\_name, password); client.EnableSsl = true; try { message = new MailMessage(new MailAddress(user\_name, display\_name), new MailAddress(To)); if (Cc != "") { string\[\] array1 = Cc.Split(','); for (int i = 0; i < array1.Length; i++) { message.CC.Add(array1\[i\].ToString()); } } if (Bcc != "") { string\[\] array2 = Bcc.Split(','); for (int i = 0; i < array2.Length; i++) { message.Bcc.Add(array2\[i\].ToString()); } } message.Body = body; message.Subject = subject; message.IsBodyHtml = true; client.Send(message); message.Dispose(); return "sent successfully"; } catch (Exception ex) { return ex.Message.ToString() + "----" + ex.InnerException.ToString(); } }
Thanks Shan
-
Hi, here is the code:
protected void Button4_Click(object sender, EventArgs e)
{
testingservice service = new testingservice();
AsyncCallback callback = new AsyncCallback(hello);
service.BeginSendMailGmail1(TextBoxto.Text.ToString(), TextBoxcc.Text.ToString(), TextBoxbcc.Text.ToString(), TextBoxbody.Text.ToString(), TextBoxsubject.Text.ToString(), TextBoxusername.Text.ToString(), TextBoxpassword.Text.ToString(), TextBoxserver.Text.ToString(), TextBoxport.Text.ToString(), TextBoxdisplayname.Text.ToString(),callback,sender);
Response.Redirect("default4.aspx");
}here is the other method but it will always be completed =true
void hello(IAsyncResult result)
{
if (!result.IsCompleted)
{
Response.Write("failed");
}
}the code for webservice:
[WebMethod]
public string SendMailGmail1(string To, string Cc, string Bcc, string body,string subject, string user\_name, string password, string server\_name, string portnumber, string display\_name) { SmtpClient client = new SmtpClient(); MailMessage message = new MailMessage(); client.Port = Convert.ToInt32(portnumber); client.Host = server\_name; client.UseDefaultCredentials = true; client.Credentials = new System.Net.NetworkCredential(user\_name, password); client.EnableSsl = true; try { message = new MailMessage(new MailAddress(user\_name, display\_name), new MailAddress(To)); if (Cc != "") { string\[\] array1 = Cc.Split(','); for (int i = 0; i < array1.Length; i++) { message.CC.Add(array1\[i\].ToString()); } } if (Bcc != "") { string\[\] array2 = Bcc.Split(','); for (int i = 0; i < array2.Length; i++) { message.Bcc.Add(array2\[i\].ToString()); } } message.Body = body; message.Subject = subject; message.IsBodyHtml = true; client.Send(message); message.Dispose(); return "sent successfully"; } catch (Exception ex) { return ex.Message.ToString() + "----" + ex.InnerException.ToString(); } }
Thanks Shan
shankbond wrote:
AsyncCallback callback = new AsyncCallback(hello);
I dont Understand why you need asychronous? here is sample code i developed now Modify your code depending on your requirement...!
//For WebService
[WebMethod]
public string SendMail()
{
try
{
MailMessage msg=new MailMessage ("From@xxx.com","To@xxx.com","Sub","body");
SmtpClient client = new SmtpClient("YourDomain", 25);
client .Send (msg);
return "hai";
}
catch (Exception ie)
{
return ie.Message ;
}
}For Calling Webservice..!
localhost.WebService rss = new localhost.WebService();
string msg=rss.SendMail();
Response.Write(msg);I am Going Bye May the group will help if you need further assistance..!:thumbsup:
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.
-
Hi, here is the code:
protected void Button4_Click(object sender, EventArgs e)
{
testingservice service = new testingservice();
AsyncCallback callback = new AsyncCallback(hello);
service.BeginSendMailGmail1(TextBoxto.Text.ToString(), TextBoxcc.Text.ToString(), TextBoxbcc.Text.ToString(), TextBoxbody.Text.ToString(), TextBoxsubject.Text.ToString(), TextBoxusername.Text.ToString(), TextBoxpassword.Text.ToString(), TextBoxserver.Text.ToString(), TextBoxport.Text.ToString(), TextBoxdisplayname.Text.ToString(),callback,sender);
Response.Redirect("default4.aspx");
}here is the other method but it will always be completed =true
void hello(IAsyncResult result)
{
if (!result.IsCompleted)
{
Response.Write("failed");
}
}the code for webservice:
[WebMethod]
public string SendMailGmail1(string To, string Cc, string Bcc, string body,string subject, string user\_name, string password, string server\_name, string portnumber, string display\_name) { SmtpClient client = new SmtpClient(); MailMessage message = new MailMessage(); client.Port = Convert.ToInt32(portnumber); client.Host = server\_name; client.UseDefaultCredentials = true; client.Credentials = new System.Net.NetworkCredential(user\_name, password); client.EnableSsl = true; try { message = new MailMessage(new MailAddress(user\_name, display\_name), new MailAddress(To)); if (Cc != "") { string\[\] array1 = Cc.Split(','); for (int i = 0; i < array1.Length; i++) { message.CC.Add(array1\[i\].ToString()); } } if (Bcc != "") { string\[\] array2 = Bcc.Split(','); for (int i = 0; i < array2.Length; i++) { message.Bcc.Add(array2\[i\].ToString()); } } message.Body = body; message.Subject = subject; message.IsBodyHtml = true; client.Send(message); message.Dispose(); return "sent successfully"; } catch (Exception ex) { return ex.Message.ToString() + "----" + ex.InnerException.ToString(); } }
Thanks Shan
-
If The Web Service is in you application Keep the break point and check wats happening in webservice..!You can track the problem..!:thumbsup:
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.
-
If The Web Service is in you application Keep the break point and check wats happening in webservice..!You can track the problem..!:thumbsup:
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.
-
shankbond wrote:
is there a way that I can add to Your reputation
I dont Know Much Abt reputation may be its new in codeproject I will Let you know After I know abt fully..!:thumbsup:
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.