【问题标题】:What is exactly hostname for sending Microsoft Exchange email with mailcore使用 mailcore 发送 Microsoft Exchange 电子邮件的确切主机名是什么
【发布时间】:2014-12-12 16:23:09
【问题描述】:

我无法使用 mailcore 发送 MS Exchange 电子邮件。 它总是返回错误“无法建立与服务器的稳定连接”。 这是我的代码

    smtpSession.hostname = @"smtp.outlook.office365.co.uk";
    smtpSession.username = [currentUser objectForKey:@"email_account"];
    smtpSession.password = [currentUser objectForKey:@"email_password"];
    smtpSession.port = 25;
    smtpSession.connectionType = MCOConnectionTypeClear;

我认为是因为主机名。 谁能告诉我在这种情况下 MS Exchange 的确切主机名是什么?

【问题讨论】:

    标签: mailcore2


    【解决方案1】:

    终于找到答案了

    smtpSession.hostname = @"smtp.office365.com";
        smtpSession.username = [currentUser objectForKey:@"email_account"];
        smtpSession.password = [currentUser objectForKey:@"email_password"];
        smtpSession.port = 25;
        smtpSession.connectionType = MCOConnectionTypeStartTLS;
    

    【讨论】:

    • 您介意发布一个使用 mailcore 发送消息的完整示例吗?
    【解决方案2】:

    以下是使用 CocoaPods 添加的 MailCore2 的完整示例,供其他人参考

    #import <MailCore/MailCore.h>
    
    MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init];
    smtpSession.hostname = @"smtp.outlook.office365.com";
    smtpSession.username = @"user@domain.com";
    smtpSession.password = @"NotMyPass";
    smtpSession.port = 587;
    smtpSession.connectionType = MCOConnectionTypeStartTLS;
    
    MCOMessageBuilder * builder = [[MCOMessageBuilder alloc] init];
    [[builder header] setFrom:[MCOAddress addressWithDisplayName:@"Me" mailbox:@"user@domain.com"]];
    [[builder header] setTo:@[[MCOAddress addressWithDisplayName:@"To you" mailbox:@"user@domain.com"]]];
    [[builder header] setSubject:@"Mailcore test"];
    [builder setTextBody:@"Message received"];
    NSData * rfc822Data = [builder data];
    
    MCOSMTPSendOperation *sendOperation = [smtpSession sendOperationWithData:rfc822Data];
    [sendOperation start:^(NSError *error) {
        if(error) {
            NSLog(@"Error sending email:%@", error);
        } else {
            NSLog(@"Successfully sent email!");
        }
    }];
    

    【讨论】:

      猜你喜欢
      • 2012-08-27
      • 2016-12-28
      • 2014-07-19
      • 2013-11-12
      • 2013-06-05
      • 1970-01-01
      • 2013-04-17
      • 2018-01-17
      • 2021-04-19
      相关资源
      最近更新 更多