我正在尝试使用 MailCore 发送电子邮件,但没有发送电子邮件。请建议我是否做错了什么。发送电子邮件的代码如下:
-(void) sendMail{
NSLog(@"entered");
CTCoreMessage *testMsg = [[CTCoreMessage alloc] init];
[testMsg setTo:[NSSet setWithObject:[CTCoreAddress addressWithName:@"recipients name" email:@"recipient@gmail.com"]]];
[testMsg setFrom:[NSSet setWithObject:[CTCoreAddress addressWithName:@"sender name(me)" email:@"my_e_mail@google.com"]]];
[testMsg setBody:@"This is a test message!"];
[testMsg setSubject:@"This is a subject"];
NSLog(@"Init values");
NSError *error;
BOOL success = [CTSMTPConnection sendMessage:testMsg
server:@"smtp.gmail.com"
username:@"my_e_mail"
password:@"pwd"
port:587
connectionType:CTSMTPConnectionTypeStartTLS
useAuth:YES
error:&error];
NSLog(@"Success is %c", success);
if (!success) {
// Present the error
NSLog(@"Mail not sent");
}
}