使用mailcore xcode中的应用程序发送电子邮件:错过邮件正文中的错误

时间:2011-11-26 11:22:30

标签: iphone objective-c ios xcode mailcore

这是执行文件。邮件是发送但问题是邮件正文中的文本缺少邮件的接收者,任何人都可以帮助我......如何纠正这个问题

@implementation MyController

- (id)init
{
    self = [super init];
    if(self)
    {
        myMessage = [[CTCoreMessage alloc] init];
    }
    return self;
}

- (void)dealloc
{
    [myMessage release];
    [super dealloc];
}

- (IBAction)sendMessage:(id)sender
{
    CTCoreMessage *msg = [[CTCoreMessage alloc] init];
    [msg setTo:[myMessage to]];
    [msg setFrom:[myMessage from]];
    [msg setBody:[myMessage body]];
    [msg setSubject:[myMessage subject]];

    BOOL auth = ([useAuth state] == NSOnState);
    BOOL tls = ([useTLS state] == NSOnState);
    [CTSMTPConnection sendMessage:msg server:[server stringValue] username:[username stringValue]
    password:[password stringValue] port:[port intValue] useTLS:tls useAuth:auth];
    [msg release];
}

- (NSString *)to
{
    return [[[myMessage to] anyObject] email];
}

- (void)setTo:(NSString *)aValue
{
    CTCoreAddress *addr = [CTCoreAddress address];
    [addr setEmail:aValue];
    [myMessage setTo:[NSSet setWithObject:addr]];
}

- (NSString *)from
{
    return [[[myMessage from] anyObject] email];
}

- (void)setFrom:(NSString *)aValue
{
    CTCoreAddress *addr = [CTCoreAddress address];
    [addr setEmail:aValue];
    [addr setName:@""];
    [myMessage setFrom:[NSSet setWithObject:addr]];
}

- (NSString *)subject
{
    return [myMessage subject];
}

- (void)setSubject:(NSString *)aValue
{
    [myMessage setSubject:aValue];
}

- (NSString *)body
{
    return [myMessage body];
}

- (void)setBody:(NSString *)aValue
{
    [myMessage setBody:aValue];
}
@end

2 个答案:

答案 0 :(得分:0)

那里有你的周期性参考,Rehana。

查看您的setBody方法。

您正在尝试将myMessage的主体设置为myMessage的当前主体。两者都是NULL。

答案 1 :(得分:0)

您需要首先在myMessage对象中设置值,而不需要再次调用相同的东西。 在这里你将如何做到这一点

- (IBAction)sendMessage:(id)sender
{
    //Assuming textfields with the names I have passed as parameter.
    //This is only for demonstration 

    //Set body to myMessage object from textview
    [self setBody:bodytextview.text];
    [self setTo:txtfTo.text];
    [self setFrom:txtfFrom.text];
    [self setSubject:txtfSubject.text];

    BOOL auth = ([useAuth state] == NSOnState);
    BOOL tls = ([useTLS state] == NSOnState);
    //Note I'm passing myMessage Object
    [CTSMTPConnection sendMessage:myMessage server:[server stringValue] username:[username stringValue]
    password:[password stringValue] port:[port intValue] useTLS:tls useAuth:auth];

}