Closed rlaferla closed 10 years ago
There is a function shared in #182 to do the check it's just not integrated into mailcore2. Yet?
That's helpful. However, if you pass any of the strings from the output of that function to providerForMX:, you don't get back anything. I guess this is because the MCOMailProvidersManager isn't configured with any data from popular mail servers like Gmail, Yahoo, etc... That would be useful if it had some rudimentary support for them.
I use it this way
NSString * mxRecord = [VTMxRecordForHostname(@"putcocoa.in")objectAtIndex:0]; //Google Apps
if (mxRecord) {
accountProvider = [[MCOMailProvidersManager sharedManager] providerForMX:mxRecord];
}
And it will work with the popular mail servers if you add the providers.json file to your project.
Thanks. The CocoaPod doesn't seem to include the providers.json file.
The CocoaPod is probably broken though.
the MX look needs to be integrated with an asynchronous call. That's a feature I'd like to provide.
I added the json file and registered it but it doesn't seem to work.
MCOMailProvidersManager * pm = [MCOMailProvidersManager sharedManager];
NSString * fileName = [[NSBundle mainBundle] pathForResource:@"providers" ofType:@"json"];
NSLog(@"fileName=%@", fileName);
[pm registerProvidersWithFilename:fileName];
NSArray * recs = VTMxRecordForHostname(@"amazon.com");
for (NSString * mxRecord in recs) {
MCOMailProvider * provider = [pm providerForMX:mxRecord];
NSLog(@"mxRecord=%@", mxRecord);
NSLog(@"provider=%@", provider);
}
More details about what doesn't work?
I've tried this with two domains so far including gmail.com and amazon.com and the provider comes back null. Maybe the file isn't being registered properly? I will take a look in the debugger...
2014-03-19 15:20:07.134 MyApp[4658:60b] fileName=/Users/myusername/Library/Application Support/iPhone Simulator/7.1/Applications/A338A371-361D-4CEC-BAA8-D57134157AA3/MyApp.app/providers.json 2014-03-19 15:20:07.143 MyApp[4658:60b] VTMxRecordForHostname:amazon.com 2014-03-19 15:20:07.156 MyApp[4658:60b] mxname=amazon-smtp.amazon.com 2014-03-19 15:20:07.157 MyApp[4658:60b] mxRecord=amazon-smtp.amazon.com 2014-03-19 15:20:07.157 MyApp[4658:60b] provider=(null)
Also, because mProviders is a private instance variable, I can't easily debug it. I'll have to subclass it or add a category method....
I also see that init already attempts to load the providers.json file so I removed that code but it still does NOT work.
MCOMailProvidersManager * pm = [MCOMailProvidersManager sharedManager]; NSArray * recs = VTMxRecordForHostname(@"gmail.com"); for (NSString * mxRecord in recs) { MCOMailProvider * provider = [pm providerForMX:mxRecord]; NSLog(@"mxRecord=%@", mxRecord); NSLog(@"provider=%@", provider);
How can I verify that the MCOMailProvidersManager class is properly loading the providers.json file?
Also, I was mistaken about using the CocoaPod. I was using the source (github). I just did a fresh pull, clean and build but it still does NOT work.
The default providers.json doesn't have a record for amazon-smtp.amazon.com. That's why it's returning nil.
Ok but what about gmail.com? That is also returning nil.
2014-03-19 15:59:43.959 MyApp[12315:60b] VTMxRecordForHostname:gmail.com 2014-03-19 15:59:43.973 MyApp[12315:60b] mxname=alt3.gmail-smtp-in.l.google.com 2014-03-19 15:59:43.973 MyApp[12315:60b] mxname=alt4.gmail-smtp-in.l.google.com 2014-03-19 15:59:43.974 MyApp[12315:60b] mxname=gmail-smtp-in.l.google.com 2014-03-19 15:59:43.974 MyApp[12315:60b] mxname=alt1.gmail-smtp-in.l.google.com 2014-03-19 15:59:43.974 MyApp[12315:60b] mxname=alt2.gmail-smtp-in.l.google.com 2014-03-19 15:59:43.974 MyApp[12315:60b] mxRecord=alt3.gmail-smtp-in.l.google.com 2014-03-19 15:59:43.974 MyApp[12315:60b] provider=(null) 2014-03-19 15:59:43.975 MyApp[12315:60b] mxRecord=alt4.gmail-smtp-in.l.google.com 2014-03-19 15:59:43.975 MyApp[12315:60b] provider=(null) 2014-03-19 15:59:43.975 MyApp[12315:60b] mxRecord=gmail-smtp-in.l.google.com 2014-03-19 15:59:43.975 MyApp[12315:60b] provider=(null) 2014-03-19 15:59:43.975 MyApp[12315:60b] mxRecord=alt1.gmail-smtp-in.l.google.com 2014-03-19 15:59:43.975 MyApp[12315:60b] provider=(null) 2014-03-19 15:59:43.976 MyApp[12315:60b] mxRecord=alt2.gmail-smtp-in.l.google.com 2014-03-19 15:59:43.976 MyApp[12315:60b] provider=(null)
Are you able to investigate with the debugger? You'll be able to access private members.
I haven't been able to. It's in the C++ code which I'm not very familiar with. If you tell me what to look for (commands), I'll try it...
Could you dig in this method? MailProvider * MailProvidersManager::providerForMX(String * hostname)
Maybe an issue has been introduced with the latest changes to this component.
I confirm the issue. I'm looking into it too.
It just an issue with MX records for gmail and others(like amazon) that are not in the providers.json For gmail, none of these 'alt4.gmail-smtp-in.l.google.com' are in the providers.
So is the fix to add these to the mx-match entry in the providers.json file?
Obviously :)
You could first try if it works if it works with dropbox.com and twitter.com. (There's hosted by Google Apps).
It does NOT seem to work. How can I tell if the json file was loaded or not?
"gmail":{ "servers":{ "imap":[ { "port":993, "hostname":"imap.gmail.com", "ssl":true } ], "smtp":[ { "port":587, "hostname":"smtp.gmail.com", "starttls":true }, { "port":465, "hostname":"smtp.gmail.com", "ssl":true }, { "port":25, "hostname":"smtp.gmail.com", "starttls":true } ] }, "mx-match":[ "aspmx2.googlemail.com", "aspmx.l.google.com", "aspmx3.googlemail.com", "alt1.aspmx.l.google.com", "alt2.aspmx.l.google.com", "alt1.gmail-smtp-in.l.google.com", "alt2.gmail-smtp-in.l.google.com", "alt3.gmail-smtp-in.l.google.com", "alt4.gmail-smtp-in.l.google.com", "gmail-smtp-in.l.google.com" ], "domain-match":[ "googlemail.com", "gmail.com" ], "mailboxes":{ "sentmail":"[Gmail]/Sent", "allmail":"[Gmail]/All Mail", "starred":"[Gmail]/Starred", "trash":"[Gmail]/Trash", "drafts":"[Gmail]/Drafts", "spam":"[Gmail]/Spam", "important":"[Gmail]/Important" } },
I tried with "twitter.com" and got two additional MX records. Still does NOT work. :-(
"mx-match":[
"aspmx2\\.googlemail\\.com",
"aspmx\\.l\\.google\\.com",
"aspmx3\\.googlemail\\.com",
"alt1\\.aspmx\\.l\\.google\\.com",
"alt2\\.aspmx\\.l\\.google\\.com",
"ASPMX2\\.GOOGLEMAIL\\.com",
"ASPMX3\\.GOOGLEMAIL\\.com",
"alt1\\.gmail-smtp-in\\.l\\.google\\.com",
"alt2\\.gmail-smtp-in\\.l\\.google\\.com",
"alt3\\.gmail-smtp-in\\.l\\.google\\.com",
"alt4\\.gmail-smtp-in\\.l\\.google\\.com",
"gmail-smtp-in\\.l\\.google\\.com"
],
Mea culpa. In the process of troubleshooting had changed the code to providerForEmail: instead of providerForMX:. It works!
MCOMailProvidersManager has a couple of methods for looking up providers:
providerForEmail: providerForMX:
However, they DO NOT appear to do a DNS MX record lookup. Instead, it appears that you need to do that lookup independently and then pass the record to providerForMX:
If this is the case, then mailcore2 should have a method to do the actual MX record lookup.
This may be helpful: http://justanapplication.wordpress.com/tag/dnsservicequeryrecord/