TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
harry code
NA
124
22.8k
Ajax function always calling error function
Mar 1 2019 7:35 AM
Hi,
I am trying to read messages from gmail and display them in juery datatable.
Ajax web method is calling error method.
here is the .cs code
public
static
void
getmessage()
{
try
{
List<
string
> ids =
new
List<
string
>();
List<AE.Net.Mail.MailMessage> mails =
new
List<AE.Net.Mail.MailMessage>();
List<Email> emaillist =
new
List<Email>();
int
count = 1;
using
(var ic =
new
AE.Net.Mail.ImapClient(
"imap.gmail.com"
,
"
[email protected]
"
,
"Abc"
, AE.Net.Mail.AuthMethods.Login, 993,
true
))
{
ic.SelectMailbox(
"INBOX"
);
int
y = ic.GetMessageCount();
MailMessage[] mm = ic.GetMessages(0, y);
var msgs = ic.SearchMessages(SearchCondition.Undeleted());
for
(
int
i =0; i < msgs.Length; i++)
{
if
(count == 500)
{
break
;
}
string
msgId = msgs[y-1].Value.Uid;
ids.Add(msgId);
y--;
count++;
}
foreach
(
string
id
in
ids)
{
mails.Add(ic.GetMessage(id, headersonly:
false
));
}
//DataTable dt = new DataTable();
foreach
(var msg
in
mails)
{
Email email =
new
Email();
Attachment attachment =
new
Attachment();
email.Body= msg.Body.ToString();
email.From = msg.From.ToString();
email.DateSent = msg.Date;
foreach
(var att
in
msg.Attachments)
{
string
fName;
fName = att.Filename;
string
bo= att.Body;
Attachment a =
new
Attachment();
a.Content = fName;
email.Attachments.Add(a);
}
//dt.Columns.Add("From", typeof(string));
//dt.Columns.Add("Subject", typeof(string));
//dt.Columns.Add("Date", typeof(DateTime));
//dt.Columns.Add("Body", typeof(string));
//DataRow dr1 = dt.NewRow();
//dr1 = dt.NewRow();
//dr1["From"] = email.From.ToString();
//dr1["Subject"] = email.Subject.ToString();
//dr1["Date"] = email.DateSent;
//dr1["Body"] = email.Body;
//dt.Rows.Add(dr1);
//DataSet ds = new DataSet();
emaillist.Add(email);
}
var js =
new
JavaScriptSerializer();
HttpContext.Current.Response.Write(js.Serialize(emaillist));
}
}
catch
(Exception exe)
{
//MessageBox.Show("Check your network connection");
}
}
here is the sample Jquery code:
$(document).ready(
function
() {
debugger
;
$.ajax({
url:
"Reademail.aspx/getmessage"
,
type:
"POST"
,
dataType:
"json"
,
contentType:
"application/json; charset=utf-8"
,
success:
function
(data)
{
debugger
;
var
datatableVariable = $(
'#tblmsg'
).DataTable(
{
data: data,
columns: [
{
'data'
:
'From'
},
{
'data'
:
'Subject'
},
{
'data'
:
'DateSent'
},
{
'data'
:
'Body'
}
]
});
},
error:
function
(){alert(
'error'
);}
});
});
Reply
Answers (
7
)
storing value after Ajax function calling
How to get JSON data on ajax call every 10secs