NSSharingService를 사용하여 메일을 작성하려고합니다. 수신자, 본문, 제목 및 첨부 파일을 추가 할 수는 있지만 보낸 사람을 추가하고 전자 메일을 자동 전송할 수는 없습니다. 발신자를 추가하고 NSSharingService를 사용하여 자동으로 이메일을 보내는 방법이 있습니까? 있다면, 어떻게 말해 줄 수 있습니까? 그렇지 않은 경우 다른 방법을 제안 할 수 있습니까? 나는 ScriptingBridge를 시도했다. 작동하도록했지만 스케줄러를 사용하여 자동으로 응용 프로그램을 실행하면 -[SBProxyByClass setSender:]: object has not been added to a container yet; selector not recognized
충돌이 발생합니다. 이것이 NSSharingService를 사용하는 새로운 접근 방식을 시도하는 이유입니다. 감사합니다. .AutoSend NSSharingService : 전자 메일
-1
A
답변
0
Apple은 사용자의 동의없이 작업을 수행하는 것에 대해 매우 엄격합니다. NSSharingService 또는 ScriptingBridge를 사용하는 대신 자동으로 처리 할 수 있기를 원하기 때문에 앱 내에 SMTP 라이브러리를 사용하는 것이 좋습니다.
Objective-C의 대중적인 라이브러리 인 것 같습니다. libmailcore입니다. 전에 사용하지는 않았지만 그것에 대해 많이 알 수는 없습니다. 메시지를 보내는 이들의 예는 충분히 간단합니다.
MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init];
smtpSession.hostname = @"smtp.gmail.com";
smtpSession.port = 465;
smtpSession.username = @"[email protected]";
smtpSession.password = @"password";
smtpSession.authType = MCOAuthTypeSASLPlain;
smtpSession.connectionType = MCOConnectionTypeTLS;
MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init];
MCOAddress *from = [MCOAddress addressWithDisplayName:@"Matt R"
mailbox:@"[email protected]"];
MCOAddress *to = [MCOAddress addressWithDisplayName:nil
mailbox:@"[email protected]"];
[[builder header] setFrom:from];
[[builder header] setTo:@[to]];
[[builder header] setSubject:@"My message"];
[builder setHTMLBody:@"This is a test message!"];
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!");
}
}];
감사합니다. 나는 그것을 시도했다. 라이브러리를 가져올 수 있었지만 시도 할 때마다 서버에 안정적으로 연결할 수 없었습니다. "이유를 이해할 수없는 것 같습니다. ( – cessmestreet
안녕하세요. 인증 유형 변경. 감사합니다. – cessmestreet