我正在尝试使用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");
}
}
2条答案
按热度按时间k0pti3hp1#
7lrncoxx2#
这是您可以使用的示例代码:
您可以在此处找到此示例代码(Sample Code)的参考。