help : Required for send mail error for second time onwards
- From: sunil kumar <bksunil80 gmail com>
- To: tinymail-devel-list gnome org
- Subject: help : Required for send mail error for second time onwards
- Date: Fri, 15 May 2009 18:46:52 +0530
Hello ,
I am developing a simple application for Tinymail 0.0.9.
Using my application, I could successfully able to send an email using
SMTP server for the first time.
However I wouldn’t able to send an email from subsequent time onwards.
I am using tny_send_queue_add_async( ) to add my message into Queue.
It is seen that in the failed case (i.e from the second time onwards),
the tny_send_queue_add_async( ) function doesn’t generate the any
signals like “queue-start”, “queue-stop” , “msg-sent” etc.
I have attached the some debug logs for both successful and failure
attempts. I have also attached my application file(sendmail) with
this mail.
Attached files:
Sendmail.cpp : Simple application which sends email
using Tinymail
library.
failure_mail.txt : Logs for failure case.
successful_mail.txt : Logs for successful case includes
Application log and
Tinymail log.
Thanks
Sunil
--
<a href="http://www.spreadfirefox.com/?q=affiliates&id=129956&t=86"><img
border="0" alt="Get Firefox!" title="Get Firefox!" src="
http://sfx-images.mozilla.org/affiliates/Buttons/125x50/takebacktheweb_125x50.png"/></a>
TnyCamelQueue: tny_camel_folder_get_headers_async_default is on the stage, now performing
TnyCamelQueue: user callback starts
EMAIL> Entering into main loop
TnyCamelQueue: user callback finished
TnyCamelQueue: tny_camel_folder_get_headers_async_default is off the stage, done performing
TnyCamelQueue: tny_camel_folder_add_msg_async_default is on the stage, now performing
EMAIL> tny_xxx_queue_start_sig(IN)
EMAIL> tny_xxx_queue_start_sig(OUT)
EMAIL> tny_xxx_queue_stop_sig(IN)
EMAIL> tny_xxx_queue_stop_sig(OUT)
TnyCamelQueue: user callback starts
EMAIL> tny_send_queue_add__async_cb(IN)
EMAIL> tny_send_queue_add__async_cb(OUT)
TnyCamelQueue: user callback finished
TnyCamelQueue: tny_camel_folder_add_msg_async_default is off the stage, done performing
TnyCamelQueue: tny_camel_folder_get_headers_async_default is on the stage, now performing
TnyCamelQueue: user callback starts
TnyCamelQueue: user callback finished
TnyCamelQueue: tny_camel_folder_get_headers_async_default is off the stage, done performing
TnyCamelQueue: tny_camel_folder_get_headers_async_default is on the stage, now performing
TnyCamelQueue: user callback starts
TnyCamelQueue: user callback finished
TnyCamelQueue: tny_camel_folder_get_headers_async_default is off the stage, done performing
EMAIL> tny_xxx_queue_start_sig(IN)
EMAIL> tny_xxx_queue_start_sig(OUT)
EMAIL> tny_send_queue_add_msg_sending_cb(IN)
EMAIL> tny_send_queue_add_msg_sending_cb(OUT)
-> EHLO [192.168.3.132]
<- 250-xxxxxx.xxx.com
<- 250-PIPELINING
<- 250-SIZE 70485760
<- 250-VRFY
<- 250-ETRN
<- 250 8BITMIME
-> MAIL FROM:<ramesh babu xxx com>
<- 250 Ok
-> RCPT TO:<ramesh babu xxx com>
<- 250 Ok
-> RCPT TO:<ramesh babu xxx com>
<- 250 Ok
-> RCPT TO:<ramesh babu xxx com>
<- 250 Ok
-> DATA
<- 354 End data with <CR><LF>.<CR><LF>
-> \r\n.\r\n
<- 250 Ok: queued as 6FFBE558005
-> RSET
<- 250 Ok
-> QUIT
TnyCamelQueue: tny_camel_folder_get_headers_async_default is on the stage, now performing
TnyCamelQueue: user callback starts
TnyCamelQueue: tny_camel_folder_get_msg_async_default is on the stage, now performing
TnyCamelQueue: user callback starts
TnyCamelQueue: user callback finished
TnyCamelQueue: tny_camel_folder_get_headers_async_default is off the stage, done performing
EMAIL> msg_queue_msg_sent_cb(IN)
EMAIL> msg_queue_msg_sent_cb(OUT)
TnyCamelQueue: user callback finished
TnyCamelQueue: tny_camel_folder_get_msg_async_default is off the stage, done performing
EMAIL> send_mail_thread(OUT)
TnyCamelQueue: tny_camel_folder_get_headers_async_default is on the stage, now performing
TnyCamelQueue: user callback starts
EMAIL> Entering into main loop
á
#include "email.h"
static GMainLoop *main_loop = NULL;
//TnyMimePart *
//attach_mime_part_with_file(gchar *path, const gchar *mime_type, const gchar *transfer_encoding)
TnyMimePart *
attach_mime_part_with_file(gchar *path, gchar *mime_type, gchar *transfer_encoding)
{
TnyMimePart *part;
TnyStream *fstream;
char *fname;
int fd;
g_print(PROMPT "attach_mime_part_with_file: %s\n", path);
fd = open(path, O_RDONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if(fd == -1) {
g_print(PROMPT "*** Error unable to open a file\n");
return NULL;
}
part = tny_camel_mime_part_new();
if(part == NULL) {
close(fd);
return NULL;
}
fname = g_path_get_basename(path);
tny_mime_part_set_filename(part, fname);
fstream = tny_fs_stream_new(fd);
tny_mime_part_construct(part, fstream, mime_type, transfer_encoding);
g_free(fname);
return part;
}
int find_file_type(char *file_name)
{
int type;
char *p;
struct stat buf;
type = -1;
g_strstrip(file_name); //_MOON_
/* file not exists return -1 */
if(g_stat(file_name, &buf) != 0)
{
perror(PROMPT "File error: ");
return type;
}
p = strrchr(file_name, '.');
if(p) {
if(strcasecmp(p + 1, "txt") == 0) {
type = 0;
}
else if(strcasecmp(p + 1, "jpg") == 0) {
type = 1;
}
}
return type;
}
char *
get_contacts_from_list(MSG_CONTACT_LIST_S *list, int contact_type)
{
int comma = 0;
int i = 0;
int count = 0;
int size = 0;
char *buffer = NULL;
MSG_CONTACT_S *contact;
if(list->iCount == 0)
return NULL;
count = list->iCount;
contact = list->pContacts;
g_print(PROMPT "No of contacts: %d\n", count);
if(contact_type == CONTACT_TYPE_TO) {
g_print(PROMPT "CONTACT_TYPE_TO\n");
}
else if(contact_type == CONTACT_TYPE_CC) {
g_print(PROMPT "CONTACT_TYPE_CC\n");
} else if(contact_type == CONTACT_TYPE_BCC) {
g_print(PROMPT "CONTACT_TYPE_BCC\n");
}
size = 0;
comma = 0;
for(i = 0; i < count; i++)
{
if(contact->contactType == (MSG_CONTACT_TYPE_T)contact_type) {
size += strlen((const char *)contact->contactVal);
comma++;
}
contact = contact + 1;
}
if(size == 0) {
return NULL;
}
buffer = (char *)malloc(size + comma + 1);
contact = list->pContacts;
int num = 0;
for(i = 0; i < count; i++)
{
if(contact->contactType == (MSG_CONTACT_TYPE_T)contact_type) {
sprintf(buffer + num, "%s,", contact->contactVal);
num=strlen(buffer);
}
contact = contact + 1;
}
/* remove last , from the string */
buffer[size + comma - 1] = '\0';
return buffer;
}
static TnyMsg*
create_send_msg(const MSG_MESSAGE_REQUEST_S *pRequest)
{
TnyMsg *msg;
TnyHeader *header;
char *to;
char *cc;
char *bcc;
msg = tny_camel_msg_new();
header = tny_msg_get_header(msg);
g_print(PROMPT "subject: %s\n", (unsigned char *)pRequest->pMsg->subject.pString);
tny_header_set_subject(header, (const gchar *)pRequest->pMsg->subject.pString);
g_print(PROMPT "from: %s\n", pRequest->pMsg->from.contactVal);
tny_header_set_from(header, (const gchar *)pRequest->pMsg->from.contactVal);
to = get_contacts_from_list(&pRequest->pMsg->to, CONTACT_TYPE_TO);
if(to != NULL) {
g_print(PROMPT "to : %s\n", to);
tny_header_set_to(header, to);
free(to);
to = NULL;
}
cc = get_contacts_from_list(&pRequest->pMsg->to, CONTACT_TYPE_CC);
if(cc != NULL) {
g_print(PROMPT "cc : %s\n", cc);
tny_header_set_cc(header, cc);
free(cc);
cc = NULL;
}
bcc = get_contacts_from_list(&pRequest->pMsg->to, CONTACT_TYPE_BCC);
if(bcc != NULL) {
g_print(PROMPT "bcc: %s\n", bcc);
tny_header_set_bcc(header, bcc);
free(bcc);
bcc = NULL;
}
g_object_unref(G_OBJECT(header));
/* empty mail */
if(pRequest->pMsg->pExtData == NULL) {
g_print(PROMPT "Empty email ...\n");
return msg;
}
EMAIL_MSG_INFO *mail_info;
mail_info = (EMAIL_MSG_INFO *)pRequest->pMsg->pExtData;
/* copy body of the email */
if(mail_info->body.text_len > 0) {
g_print("text length %d\n", mail_info->body.text_len);
TnyStream *stream;
TnyMimePart *mime_body_part;
char *mime_type;
EMAIL_TEXT *body;
body = &mail_info->body;
if(email_charset_get(body->text_charset)) {
mime_type = g_strdup_printf("%s; charset=%s", body->text_mime_type,
email_charset_get(body->text_charset));
}
else {
mime_type = g_strdup_printf("%s", body->text_mime_type);
}
g_print(PROMPT "body - text_encoding: %s\n", email_encoding_get(mail_info->body.text_encoding));
g_print(PROMPT "body - text_charset : %s\n", email_charset_get(body->text_charset));
g_print(PROMPT "body - text_mimetyep: %s\n", mime_type);
g_print(PROMPT "body - text_len : %d\n", mail_info->body.text_len);
g_print(PROMPT "body - text_data : %s\n", mail_info->body.text_data);
stream = tny_camel_mem_stream_new();
tny_stream_write(stream, mail_info->body.text_data, mail_info->body.text_len);
tny_stream_reset(stream);
mime_body_part = tny_camel_mime_part_new();
tny_mime_part_construct(mime_body_part, stream, mime_type, email_encoding_get(mail_info->body.text_encoding));
tny_mime_part_add_part(TNY_MIME_PART(msg), mime_body_part);
g_object_unref(G_OBJECT(mime_body_part));
g_object_unref(G_OBJECT(stream));
if(mime_type)
g_free(mime_type);
}
else
{
g_print(PROMPT "Body text not found\n");
}
/* handle attachments */
g_print(PROMPT "Number of attachments: %d\n", mail_info->attachments.iCount);
if(mail_info->attachments.iCount > 0)
{
char *mime_type;
int i =0;
TnyMimePart *mime_file_part;
EMAIL_TEXT_LIST *att;
att = &mail_info->attachments;
for(i = 0; i < att->iCount; i++) {
g_print(PROMPT "Attachemnt: %d\n", i);
g_print(PROMPT "\tmime : %s\n", att->attachments[i].text_mime_type);
g_print(PROMPT "\ttext_encoding : %d\n", att->attachments[i].text_encoding);
g_print(PROMPT "\ttext_charset : %d\n", att->attachments[i].text_charset);
g_print(PROMPT "\ttext_mime_type: %s\n", att->attachments[i].text_mime_type);
g_print(PROMPT "\ttext_len : %d\n", att->attachments[i].text_len);
g_print(PROMPT "\ttext_data : %s\n", att->attachments[i].text_data);
if(email_charset_get(att->attachments[i].text_charset))
mime_type = g_strdup_printf("%s; charset=%s", att->attachments[i].text_mime_type,
email_charset_get(att->attachments[i].text_charset));
else
mime_type = att->attachments[i].text_mime_type;
g_print(PROMPT "text_encoding: %s\n", email_encoding_get(att->attachments[i].text_encoding));
g_print(PROMPT "text_charset : %s\n", email_charset_get(att->attachments[i].text_charset));
g_print(PROMPT "text_mimetype : %s\n", mime_type);
mime_file_part = attach_mime_part_with_file(att->attachments[i].text_data, att->attachments[i].text_mime_type,
email_encoding_get(att->attachments[i].text_encoding));
if(mime_file_part)
{
g_printf("attachment %d - attaching mime_file_part\n", i);
tny_mime_part_add_part(TNY_MIME_PART(msg), mime_file_part);
g_object_unref(G_OBJECT(mime_file_part));
}
}
}
else
{
g_print(PROMPT "No attachments found\n");
}
return msg;
}
void
tny_send_queue_add_error_happened_cb(TnySendQueue *self, TnyHeader *arg1,
TnyMsg *arg2, gpointer arg3, gpointer data)
{
MSG_MESSAGE_REQUEST_S *pRequest;
g_print(PROMPT "tny_send_queue_add_error_happened_cb(IN)\n");
UNUSED(self);UNUSED(arg1);UNUSED(arg2);/*UNUSED(arg3);*/
pRequest = (MSG_MESSAGE_REQUEST_S *)data;
g_print(PROMPT "Error code : %d",*(guint*)arg3);
email_status_changed(pRequest, true, MSG_STATUS_FAIL_TO_SEND, EMAIL_PLUGIN_ERR_DEVICE_FAILED);
g_main_loop_quit(main_loop);
g_print(PROMPT "tny_send_queue_add_error_happened_cb(OUT)\n");
}
void
msg_queue_msg_sent_cb(TnySendQueue *self, TnyHeader *arg1,TnyMsg *arg2,
guint arg3, guint arg4, gpointer data)
{
MSG_MESSAGE_REQUEST_S *pRequest;
g_print(PROMPT "msg_queue_msg_sent_cb(IN)\n");
UNUSED(self);UNUSED(arg1);UNUSED(arg2);UNUSED(arg3);UNUSED(arg4);
pRequest = (MSG_MESSAGE_REQUEST_S *)data;
email_status_changed(pRequest, true, MSG_STATUS_SENT, MSG_SUCCESS);
g_main_loop_quit(main_loop);
g_print(PROMPT "msg_queue_msg_sent_cb(OUT)\n");
}
void
tny_xxx_queue_start_sig(TnySendQueue *self, TnyHeader *arg1,TnyMsg *arg2,
guint arg3, guint arg4, gpointer data)
{
MSG_MESSAGE_REQUEST_S *pRequest;
g_print(PROMPT "tny_xxx_queue_start_sig(IN)\n");
UNUSED(self);UNUSED(arg1);UNUSED(arg2);UNUSED(arg3);UNUSED(arg4);
/*
pRequest = (MSG_MESSAGE_REQUEST_S *)data;
email_status_changed(pRequest, true, MSG_STATUS_SENT, MSG_SUCCESS);
g_main_loop_quit(main_loop);
*/
g_print(PROMPT "tny_xxx_queue_start_sig(OUT)\n");
}
void
tny_xxx_queue_stop_sig(TnySendQueue *self, TnyHeader *arg1,TnyMsg *arg2,
guint arg3, guint arg4, gpointer data)
{
MSG_MESSAGE_REQUEST_S *pRequest;
g_print(PROMPT "tny_xxx_queue_stop_sig(IN)\n");
UNUSED(self);UNUSED(arg1);UNUSED(arg2);UNUSED(arg3);UNUSED(arg4);
/*
pRequest = (MSG_MESSAGE_REQUEST_S *)data;
email_status_changed(pRequest, true, MSG_STATUS_SENT, MSG_SUCCESS);
g_main_loop_quit(main_loop);
*/
g_print(PROMPT "tny_xxx_queue_stop_sig(OUT)\n");
}
void tny_send_queue_add_msg_sending_cb(TnySendQueue *self, TnyHeader *arg1,
TnyMsg *arg2, guint arg3, guint arg4, gpointer data)
{
MSG_MESSAGE_REQUEST_S *pRequest;
g_print(PROMPT "tny_send_queue_add_msg_sending_cb(IN)\n");
UNUSED(self);UNUSED(arg1);UNUSED(arg2);UNUSED(arg3);UNUSED(arg4);
pRequest = (MSG_MESSAGE_REQUEST_S *)data;
email_status_changed(pRequest, false, MSG_STATUS_SENDING, MSG_SUCCESS);
g_print(PROMPT "tny_send_queue_add_msg_sending_cb(OUT)\n");
}
void tny_send_queue_add__async_cb(TnySendQueue *self, gboolean cancelled, TnyMsg *msg, GError *err, gpointer data)
{
UNUSED(self);UNUSED(cancelled);UNUSED(msg);UNUSED(err);UNUSED(data);
g_print(PROMPT "tny_send_queue_add__async_cb(IN)\n");
g_print(PROMPT "tny_send_queue_add__async_cb(OUT)\n");
}
gpointer
send_mail_thread(gpointer data)
{
MSG_MESSAGE_REQUEST_S *pRequest;
TnyAccountStore *account_store;
TnyAccount *account;
TnyMsg *msg;
TnyDevice *device;
TnySendQueue *queue;
g_print(PROMPT "send_mail_thread(IN)\n");
pRequest = (MSG_MESSAGE_REQUEST_S *)data;
main_loop = g_main_loop_new(NULL, FALSE);
g_print(PROMPT "Getting ........the Account Store.\n");
account_store = tny_xxx_account_store_new();
if(account_store == NULL) {
email_status_changed(pRequest, true, MSG_STATUS_FAIL_TO_SEND, EMAIL_PLUGIN_ERR_ACCOUNT_CONNECTION_ERROR);
msg_request_free(pRequest);
g_print(PROMPT "*** error unable to create account store\n");
g_print(PROMPT "send_mail(OUT)\n");
return NULL;
}
g_print(PROMPT "Got the new Store Account\n");
g_print(PROMPT "Getting Default SMTP account\n");
account = tny_xxx_account_store_get_default_smtp_account(account_store);
if(account == NULL)
{
email_status_changed(pRequest, true, MSG_STATUS_FAIL_TO_SEND, EMAIL_PLUGIN_ERR_ACCOUNT_CONNECTION_ERROR);
msg_request_free(pRequest);
g_object_unref(G_OBJECT(account_store));
g_print(PROMPT "*** error unable to create default account\n");
g_print(PROMPT "send_mail(OUT)\n");
return NULL;
}
g_print(PROMPT "Got the defailt the SMTP account\n");
g_print(PROMPT "Get the device online\n");
/* put device into online state */
device = tny_account_store_get_device(account_store);
tny_device_force_online(device);
if(!tny_device_is_online(device)) {
email_status_changed(pRequest, true, MSG_STATUS_FAIL_TO_SEND, EMAIL_PLUGIN_ERR_DEVICE_NOT_READY);
msg_request_free(pRequest);
g_object_unref(G_OBJECT(device));
g_object_unref(G_OBJECT(account));
g_object_unref(G_OBJECT(account_store));
g_print(PROMPT "device status: offline\n");
g_print(PROMPT "send_mail(OUT)\n");
return NULL;
}
g_print(PROMPT "device status: online\n");
msg = create_send_msg(pRequest);
queue = tny_camel_send_queue_new(TNY_CAMEL_TRANSPORT_ACCOUNT(account));
if(queue == NULL) {
email_status_changed(pRequest, true, MSG_STATUS_READ, EMAIL_PLUGIN_ERR_DEVICE_NOT_READY);
msg_request_free(pRequest);
g_object_unref(G_OBJECT(msg));
g_object_unref(G_OBJECT(device));
g_object_unref(G_OBJECT(account));
g_object_unref(G_OBJECT(account_store));
g_print(PROMPT "error in creating send queue.....\n");
g_print(PROMPT "send_mail(OUT)\n");
return NULL;
}
g_signal_connect(queue, "msg-sending", G_CALLBACK(tny_send_queue_add_msg_sending_cb), (gpointer)pRequest);
g_signal_connect(queue, "msg-sent", G_CALLBACK(msg_queue_msg_sent_cb), (gpointer)pRequest);
g_signal_connect(queue, "error-happened", G_CALLBACK(tny_send_queue_add_error_happened_cb), (gpointer)pRequest);
g_signal_connect(queue, "queue-start", G_CALLBACK(tny_xxx_queue_start_sig), (gpointer)pRequest);
g_signal_connect(queue, "queue-stop", G_CALLBACK(tny_xxx_queue_stop_sig), (gpointer)pRequest);
g_print(PROMPT "Add the message into the queue.\n");
tny_send_queue_add_async(queue, msg, tny_send_queue_add__async_cb, NULL, NULL);
g_print(PROMPT "Entering into main loop\n");
g_main_loop_run(main_loop);
g_main_loop_unref(main_loop);
// tny_device_force_offline(device);
msg_request_free(pRequest);
g_object_unref(G_OBJECT(queue));
g_object_unref(G_OBJECT(msg));
g_object_unref(G_OBJECT(device));
g_object_unref(G_OBJECT(account));
g_object_unref(G_OBJECT(account_store));
g_print(PROMPT "send_mail_thread(OUT)\n");
return NULL;
}
MSG_ERROR_T
send_request_handle(MSG_MESSAGE_REQUEST_S *pRequest)
{
pthread_t thread_id;
int ret_val;
g_print(PROMPT "send_request_handle(IN)\n");
ret_val = pthread_create(&thread_id, NULL, send_mail_thread, (gpointer)pRequest);
if(ret_val != 0) {
g_print(PROMPT "*** pthread_create error\n");
return EMAIL_PLUGIN_ERR_PTHREAD_CREATION;
}
g_print(PROMPT "send_request_handle(OUT)\n");
return MSG_SUCCESS;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]