librelist archives

« back to archive

No body, subject and attachments after message is sent

No body, subject and attachments after message is sent

From:
Denis Kutlubaev
Date:
2012-10-04 @ 16:26
I send a message, that I generate myself. Sometimes it comes to the 
receiver normally, sometimes it is empty. 
What might be the reason? 

[CTSMTPConnection sendMessage:self.coreMessage server:mcAccount.outServer 
username:mcAccount.userName password:mcAccount.pwd port:mcAccount.outPort 
useTLS:mcAccount.outSSLOn useAuth:YES error:&error];
    
    if (error) {
        success = NO;
        NSLog(@"Error:%@", [error description]);
    }
    else {
        success = YES;
    }

I never get errors. I got an error only once, when I was debugging line by line.

This is how I create a message

- (void)createMessageFromInput
{
    // Конструируем сообщение перед отправкой
    CTCoreMessage *coreMessage = [[CTCoreMessage alloc] init];
    
    // To
    NSMutableSet *toSet = [[NSMutableSet alloc] init];
    for (NSString *eMail in _toRecipients) {
        NSLog(@"Adding email:%@", eMail);
        CTCoreAddress *addr = [CTCoreAddress address];
        [addr setEmail:eMail];
        [toSet addObject:addr];
    }
    [coreMessage setTo:[NSSet setWithSet:toSet]];
    
    // From
    CTCoreAddress *addrFrom = [CTCoreAddress address];
    [addrFrom setEmail:self.mcAccount.eMailAddress];
    [addrFrom setName:self.mcAccount.fullName];
    [coreMessage setFrom:[NSSet setWithObject:addrFrom]];
    
    // Cc
    NSMutableSet *ccSet = [[NSMutableSet alloc] init];
    for (NSString *eMail in _ccRecipients) {
        CTCoreAddress *addr = [CTCoreAddress address];
        [addr setEmail:eMail];
        [ccSet addObject:addr];
    }
    if ([ccSet count]>0) {
        [coreMessage setCc:[NSSet setWithSet:ccSet]];
    }
    
    // Bcc
    NSMutableSet *bccSet = [[NSMutableSet alloc] init];
    for (NSString *eMail in _bccRecipients) {
        CTCoreAddress *addr = [CTCoreAddress address];
        [addr setEmail:eMail];
        [bccSet addObject:addr];
    }
    if ([bccSet count]>0) {
        [coreMessage setBcc:[NSSet setWithSet:bccSet]];
    }
    
    // Subject
    NSString *string = _subjectField.text;
    NSLog(@"Subject:%@", string);
    if (!string) {
        string = @"";
    }
    NSLog(@"Subject:%@", string);
    [coreMessage setSubject:string];
    
    // Body
    string = _textView.text;
    NSLog(@"textView.text:%@", string);
    if (!string) {
        string = @"";
    }
    NSLog(@"textView.text:%@", string);
    [coreMessage setBody:string];
    
    // Set Attachments
    AppDelegate *appDel = AppDel;
    NSLog(@"Attached Docs count:%d", [attachedDocs count]);
    
    for (MCDocument *mcDocument in attachedDocs) {
        CTCoreAttachment *attach = [[CTCoreAttachment alloc] 
initWithContentsOfFile:mcDocument.path];
        if ([attach data]==nil) {
            NSLog(@"Error: attachment data is nil");
        }
        [coreMessage addAttachment:attach];
    }
    
    NSLog(@"CTCoreMessage:%@", coreMessage);
    
    self.mcMessage = [[MCMessage alloc] init];
    self.mcMessage.coreMessage = coreMessage;
}

Re: [mailcore] No body, subject and attachments after message is sent

From:
Denis Kutlubaev
Date:
2012-10-04 @ 18:00
I can also tell, that the problem is definetely somewhere here: 

- (NSString *)render {
    MMAPString * str = mmap_string_new("");
    int col = 0;
    int err = 0;
    NSString *resultStr;

    struct mailmime *mime = [self buildMIMEStruct];
    mailmime_write_mem(str, &col, mime);
    err = mmap_string_ref(str);
    resultStr = [[NSString alloc] initWithBytes:str->str length:str->len
                    encoding:NSUTF8StringEncoding];
    mmap_string_free(str);
    mailmime_free(mime);
    
    NSLog(@"resultStr:%@", resultStr);
    return [resultStr autorelease];
}

because I send same e-mail and resultStr is returned nil or not nil randomly.

04.10.2012, в 20:26, Denis Kutlubaev <kutlubaev.denis@gmail.com> написал(а):

> I send a message, that I generate myself. Sometimes it comes to the 
receiver normally, sometimes it is empty. 
> What might be the reason? 
> 
> [CTSMTPConnection sendMessage:self.coreMessage 
server:mcAccount.outServer username:mcAccount.userName 
password:mcAccount.pwd port:mcAccount.outPort useTLS:mcAccount.outSSLOn 
useAuth:YES error:&error];
>     
>     if (error) {
>         success = NO;
>         NSLog(@"Error:%@", [error description]);
>     }
>     else {
>         success = YES;
>     }
> 
> I never get errors. I got an error only once, when I was debugging line by line.
> 
> This is how I create a message
> 
> - (void)createMessageFromInput
> {
>     // Конструируем сообщение перед отправкой
>     CTCoreMessage *coreMessage = [[CTCoreMessage alloc] init];
>     
>     // To
>     NSMutableSet *toSet = [[NSMutableSet alloc] init];
>     for (NSString *eMail in _toRecipients) {
>         NSLog(@"Adding email:%@", eMail);
>         CTCoreAddress *addr = [CTCoreAddress address];
>         [addr setEmail:eMail];
>         [toSet addObject:addr];
>     }
>     [coreMessage setTo:[NSSet setWithSet:toSet]];
>     
>     // From
>     CTCoreAddress *addrFrom = [CTCoreAddress address];
>     [addrFrom setEmail:self.mcAccount.eMailAddress];
>     [addrFrom setName:self.mcAccount.fullName];
>     [coreMessage setFrom:[NSSet setWithObject:addrFrom]];
>     
>     // Cc
>     NSMutableSet *ccSet = [[NSMutableSet alloc] init];
>     for (NSString *eMail in _ccRecipients) {
>         CTCoreAddress *addr = [CTCoreAddress address];
>         [addr setEmail:eMail];
>         [ccSet addObject:addr];
>     }
>     if ([ccSet count]>0) {
>         [coreMessage setCc:[NSSet setWithSet:ccSet]];
>     }
>     
>     // Bcc
>     NSMutableSet *bccSet = [[NSMutableSet alloc] init];
>     for (NSString *eMail in _bccRecipients) {
>         CTCoreAddress *addr = [CTCoreAddress address];
>         [addr setEmail:eMail];
>         [bccSet addObject:addr];
>     }
>     if ([bccSet count]>0) {
>         [coreMessage setBcc:[NSSet setWithSet:bccSet]];
>     }
>     
>     // Subject
>     NSString *string = _subjectField.text;
>     NSLog(@"Subject:%@", string);
>     if (!string) {
>         string = @"";
>     }
>     NSLog(@"Subject:%@", string);
>     [coreMessage setSubject:string];
>     
>     // Body
>     string = _textView.text;
>     NSLog(@"textView.text:%@", string);
>     if (!string) {
>         string = @"";
>     }
>     NSLog(@"textView.text:%@", string);
>     [coreMessage setBody:string];
>     
>     // Set Attachments
>     AppDelegate *appDel = AppDel;
>     NSLog(@"Attached Docs count:%d", [attachedDocs count]);
>     
>     for (MCDocument *mcDocument in attachedDocs) {
>         CTCoreAttachment *attach = [[CTCoreAttachment alloc] 
initWithContentsOfFile:mcDocument.path];
>         if ([attach data]==nil) {
>             NSLog(@"Error: attachment data is nil");
>         }
>         [coreMessage addAttachment:attach];
>     }
>     
>     NSLog(@"CTCoreMessage:%@", coreMessage);
>     
>     self.mcMessage = [[MCMessage alloc] init];
>     self.mcMessage.coreMessage = coreMessage;
> }

Re: [mailcore] No body, subject and attachments after message is sent

From:
Matt Ronge
Date:
2012-10-09 @ 01:17
I just pushed a commit that changes MailCore so that it uses quoted 
printable for encoding messages. It may have been that if a non-ASCII 
character was in the message the result was nil. Give it a try with the 
latest code from Github and let me know if it works better.

On Oct 4, 2012, at 1:00 PM, Denis Kutlubaev <kutlubaev.denis@gmail.com> wrote:

> I can also tell, that the problem is definetely somewhere here: 
> 
> - (NSString *)render {
>     MMAPString * str = mmap_string_new("");
>     int col = 0;
>     int err = 0;
>     NSString *resultStr;
> 
>     struct mailmime *mime = [self buildMIMEStruct];
>     mailmime_write_mem(str, &col, mime);
>     err = mmap_string_ref(str);
>     resultStr = [[NSString alloc] initWithBytes:str->str length:str->len
>                     encoding:NSUTF8StringEncoding];
>     mmap_string_free(str);
>     mailmime_free(mime);
>     
>     NSLog(@"resultStr:%@", resultStr);
>     return [resultStr autorelease];
> }
> 
> because I send same e-mail and resultStr is returned nil or not nil randomly.
> 
> 04.10.2012, в 20:26, Denis Kutlubaev <kutlubaev.denis@gmail.com> написал(а):
> 
>> I send a message, that I generate myself. Sometimes it comes to the 
receiver normally, sometimes it is empty. 
>> What might be the reason? 
>> 
>> [CTSMTPConnection sendMessage:self.coreMessage 
server:mcAccount.outServer username:mcAccount.userName 
password:mcAccount.pwd port:mcAccount.outPort useTLS:mcAccount.outSSLOn 
useAuth:YES error:&error];
>>     
>>     if (error) {
>>         success = NO;
>>         NSLog(@"Error:%@", [error description]);
>>     }
>>     else {
>>         success = YES;
>>     }
>> 
>> I never get errors. I got an error only once, when I was debugging line
by line.
>> 
>> This is how I create a message
>> 
>> - (void)createMessageFromInput
>> {
>>     // Конструируем сообщение перед отправкой
>>     CTCoreMessage *coreMessage = [[CTCoreMessage alloc] init];
>>     
>>     // To
>>     NSMutableSet *toSet = [[NSMutableSet alloc] init];
>>     for (NSString *eMail in _toRecipients) {
>>         NSLog(@"Adding email:%@", eMail);
>>         CTCoreAddress *addr = [CTCoreAddress address];
>>         [addr setEmail:eMail];
>>         [toSet addObject:addr];
>>     }
>>     [coreMessage setTo:[NSSet setWithSet:toSet]];
>>     
>>     // From
>>     CTCoreAddress *addrFrom = [CTCoreAddress address];
>>     [addrFrom setEmail:self.mcAccount.eMailAddress];
>>     [addrFrom setName:self.mcAccount.fullName];
>>     [coreMessage setFrom:[NSSet setWithObject:addrFrom]];
>>     
>>     // Cc
>>     NSMutableSet *ccSet = [[NSMutableSet alloc] init];
>>     for (NSString *eMail in _ccRecipients) {
>>         CTCoreAddress *addr = [CTCoreAddress address];
>>         [addr setEmail:eMail];
>>         [ccSet addObject:addr];
>>     }
>>     if ([ccSet count]>0) {
>>         [coreMessage setCc:[NSSet setWithSet:ccSet]];
>>     }
>>     
>>     // Bcc
>>     NSMutableSet *bccSet = [[NSMutableSet alloc] init];
>>     for (NSString *eMail in _bccRecipients) {
>>         CTCoreAddress *addr = [CTCoreAddress address];
>>         [addr setEmail:eMail];
>>         [bccSet addObject:addr];
>>     }
>>     if ([bccSet count]>0) {
>>         [coreMessage setBcc:[NSSet setWithSet:bccSet]];
>>     }
>>     
>>     // Subject
>>     NSString *string = _subjectField.text;
>>     NSLog(@"Subject:%@", string);
>>     if (!string) {
>>         string = @"";
>>     }
>>     NSLog(@"Subject:%@", string);
>>     [coreMessage setSubject:string];
>>     
>>     // Body
>>     string = _textView.text;
>>     NSLog(@"textView.text:%@", string);
>>     if (!string) {
>>         string = @"";
>>     }
>>     NSLog(@"textView.text:%@", string);
>>     [coreMessage setBody:string];
>>     
>>     // Set Attachments
>>     AppDelegate *appDel = AppDel;
>>     NSLog(@"Attached Docs count:%d", [attachedDocs count]);
>>     
>>     for (MCDocument *mcDocument in attachedDocs) {
>>         CTCoreAttachment *attach = [[CTCoreAttachment alloc] 
initWithContentsOfFile:mcDocument.path];
>>         if ([attach data]==nil) {
>>             NSLog(@"Error: attachment data is nil");
>>         }
>>         [coreMessage addAttachment:attach];
>>     }
>>     
>>     NSLog(@"CTCoreMessage:%@", coreMessage);
>>     
>>     self.mcMessage = [[MCMessage alloc] init];
>>     self.mcMessage.coreMessage = coreMessage;
>> }
> 

Re: [mailcore] No body, subject and attachments after message is sent

From:
Denis Kutlubaev
Date:
2012-10-29 @ 17:05
I tried this, didn't work still. Render method returns nil. 

I created my own MIME generator. It doesn't use LibEtPan to create MIMEs. 
Only to send. It's pretty easy and cleaner to create MIME using 
Objective-C. I can give this method to you, but it's strongly bound to my 
data model objects. 

09.10.2012, в 5:17, Matt Ronge <mronge@mronge.com> написал(а):

> I just pushed a commit that changes MailCore so that it uses quoted 
printable for encoding messages. It may have been that if a non-ASCII 
character was in the message the result was nil. Give it a try with the 
latest code from Github and let me know if it works better.
> 
> On Oct 4, 2012, at 1:00 PM, Denis Kutlubaev <kutlubaev.denis@gmail.com> wrote:
> 
>> I can also tell, that the problem is definetely somewhere here: 
>> 
>> - (NSString *)render {
>>    MMAPString * str = mmap_string_new("");
>>    int col = 0;
>>    int err = 0;
>>    NSString *resultStr;
>> 
>>    struct mailmime *mime = [self buildMIMEStruct];
>>    mailmime_write_mem(str, &col, mime);
>>    err = mmap_string_ref(str);
>>    resultStr = [[NSString alloc] initWithBytes:str->str length:str->len
>>                    encoding:NSUTF8StringEncoding];
>>    mmap_string_free(str);
>>    mailmime_free(mime);
>> 
>>    NSLog(@"resultStr:%@", resultStr);
>>    return [resultStr autorelease];
>> }
>> 
>> because I send same e-mail and resultStr is returned nil or not nil randomly.
>> 
>> 04.10.2012, в 20:26, Denis Kutlubaev <kutlubaev.denis@gmail.com> написал(а):
>> 
>>> I send a message, that I generate myself. Sometimes it comes to the 
receiver normally, sometimes it is empty. 
>>> What might be the reason? 
>>> 
>>> [CTSMTPConnection sendMessage:self.coreMessage 
server:mcAccount.outServer username:mcAccount.userName 
password:mcAccount.pwd port:mcAccount.outPort useTLS:mcAccount.outSSLOn 
useAuth:YES error:&error];
>>> 
>>>    if (error) {
>>>        success = NO;
>>>        NSLog(@"Error:%@", [error description]);
>>>    }
>>>    else {
>>>        success = YES;
>>>    }
>>> 
>>> I never get errors. I got an error only once, when I was debugging 
line by line.
>>> 
>>> This is how I create a message
>>> 
>>> - (void)createMessageFromInput
>>> {
>>>    // Конструируем сообщение перед отправкой
>>>    CTCoreMessage *coreMessage = [[CTCoreMessage alloc] init];
>>> 
>>>    // To
>>>    NSMutableSet *toSet = [[NSMutableSet alloc] init];
>>>    for (NSString *eMail in _toRecipients) {
>>>        NSLog(@"Adding email:%@", eMail);
>>>        CTCoreAddress *addr = [CTCoreAddress address];
>>>        [addr setEmail:eMail];
>>>        [toSet addObject:addr];
>>>    }
>>>    [coreMessage setTo:[NSSet setWithSet:toSet]];
>>> 
>>>    // From
>>>    CTCoreAddress *addrFrom = [CTCoreAddress address];
>>>    [addrFrom setEmail:self.mcAccount.eMailAddress];
>>>    [addrFrom setName:self.mcAccount.fullName];
>>>    [coreMessage setFrom:[NSSet setWithObject:addrFrom]];
>>> 
>>>    // Cc
>>>    NSMutableSet *ccSet = [[NSMutableSet alloc] init];
>>>    for (NSString *eMail in _ccRecipients) {
>>>        CTCoreAddress *addr = [CTCoreAddress address];
>>>        [addr setEmail:eMail];
>>>        [ccSet addObject:addr];
>>>    }
>>>    if ([ccSet count]>0) {
>>>        [coreMessage setCc:[NSSet setWithSet:ccSet]];
>>>    }
>>> 
>>>    // Bcc
>>>    NSMutableSet *bccSet = [[NSMutableSet alloc] init];
>>>    for (NSString *eMail in _bccRecipients) {
>>>        CTCoreAddress *addr = [CTCoreAddress address];
>>>        [addr setEmail:eMail];
>>>        [bccSet addObject:addr];
>>>    }
>>>    if ([bccSet count]>0) {
>>>        [coreMessage setBcc:[NSSet setWithSet:bccSet]];
>>>    }
>>> 
>>>    // Subject
>>>    NSString *string = _subjectField.text;
>>>    NSLog(@"Subject:%@", string);
>>>    if (!string) {
>>>        string = @"";
>>>    }
>>>    NSLog(@"Subject:%@", string);
>>>    [coreMessage setSubject:string];
>>> 
>>>    // Body
>>>    string = _textView.text;
>>>    NSLog(@"textView.text:%@", string);
>>>    if (!string) {
>>>        string = @"";
>>>    }
>>>    NSLog(@"textView.text:%@", string);
>>>    [coreMessage setBody:string];
>>> 
>>>    // Set Attachments
>>>    AppDelegate *appDel = AppDel;
>>>    NSLog(@"Attached Docs count:%d", [attachedDocs count]);
>>> 
>>>    for (MCDocument *mcDocument in attachedDocs) {
>>>        CTCoreAttachment *attach = [[CTCoreAttachment alloc] 
initWithContentsOfFile:mcDocument.path];
>>>        if ([attach data]==nil) {
>>>            NSLog(@"Error: attachment data is nil");
>>>        }
>>>        [coreMessage addAttachment:attach];
>>>    }
>>> 
>>>    NSLog(@"CTCoreMessage:%@", coreMessage);
>>> 
>>>    self.mcMessage = [[MCMessage alloc] init];
>>>    self.mcMessage.coreMessage = coreMessage;
>>> }
>> 
> 

С уважением и наилучшими пожеланиями, 
Кутлубаев Денис
CEO, Alwawee
E-mail: kutlubaev.denis@gmail.com
Skype: IL2Shturmovik
ICQ: 5075827
Twitter: wzbozon