Bring Kmail account online automatically

I’ve recently moved from Kubuntu to Tumbleweed. I used to have Kmail running in the system tray and auto-staring at boot.

Something I really like about openSUSE (probably possible with Kubuntu too, but I never knew!) is how Kontact is configured to bring email, calendar, contact info in the same place. I have enabled the kmail icon in the system tray, which now loads kontact witht the kmail tab selected (this is great, just what I wanted).

However, there’s one thing that has been annoying me: when I boot my laptop and the wifi connects (very slowly compared to Kubuntu!) my email account doesn’t come online automatically. The account is set to poll every 5 minutes, and even if I leave it longer than that it still doesn’t connect.

I found I have to go into accounts and hit “Restart” to get it to connect. What am I doing wrong? It seems Kontact / Kmail isn’t able to automatically detect when the system has a working internet connection.

Sorry to bump this, but I’ve spent a lot of time searching and I still haven’t found a solution.

Am I the only person having this issue?

You could save sessions then all (well most) open programs will restart. or you could put a shortcut into the start directory

Thanks for the suggestion.

Kmail runs at startup, it’s just that the account within kmail shows as offline even though I have an internet connection :s

I think you’re missing some point here. It’s not kmail itself, but rather akonadi that tries. Which is not a problem when there’s no networkconnection available at start. It’ll simply try again. But … when kmail ( which relies on akonadi ) is started and detects accounts as off-line, that’s another thing, it sets the status of the accounts to off-line ( which you’re experiencing ). This tells akonadi not to try syncing the accounts.
Example: I don’t autostart kmail (or kontact), but I do see akonadi notifications about mail dropping in. Most of the time within a minute after having an internet connection.

What can you do?

  • Start kontact manually after the wifi connection has been established
  • Edit the autostarter and change the command from f.e.
/usr/bin/kmail

to

sleep 60;/usr/bin/kmail

. This would add a 60 second delay before actually starting kmail

Ah, I had no idea Akonadi managed that part of the process.

I actually don’t have either Kmail or Kontact set to autostart in the KDE control module, but it must be started when I boot because the Kmail icon is in the tray…?

Is it possible that doing things this way means that akonadi doesn’t actually autostart?

If NM is used then setting it to “All user may connect to this network” will start it sooner

I’ll give it a try, thank you.

Is it faster because the password is stored in /etc/NetworkManager/system-connections/foo instead of in a kwallet, so the system can get to the information sooner in the boot process?

Well by default MN only connects when a user logs in. checking the box to all all sets things to allow all users and thus can be started before any user logs in.

Note just because you may have auto login does not mean a user is not logged in.

I am now getting asked for the root password to connect to the wifi when I boot, I guess this is a polkit thing? Ironically, it now takes even longer to connect because of the time it takes to type the password.

I really don’t want to have to enter the root password to connect to a known wifi network (I’m ok with requiring the pw to add or modify a connection though), but I also want to connect to wifi as quickly after booting as I could on Kubuntu.

Is there a group I can add my user to so that I can connect to known wifi networks without authenticating? Or do I have to do it with polkit?

I’ve spent some time reading about polkit, but it seems all of the docs online are for the old policykit, not polkit-1.

So, I’ve been reading the man pages and Arch wiki, and comparing the configuration files on Kubuntu 14.04 to openSUSE. Here’s Kubuntu:

sam@kubuntu:~$ cat  /usr/share/polkit-1/actions/org.freedesktop.NetworkManager.policy |  egrep -v '[description|message] xml'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
 "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
<policyconfig>

  <vendor>NetworkManager</vendor>
  <vendor_url>http://www.gnome.org/projects/NetworkManager</vendor_url>
  <icon_name>nm-icon</icon_name>

  <action id="org.freedesktop.NetworkManager.enable-disable-network">
    <description>Enable or disable system networking</description>
    <message>System policy prevents enabling or disabling system networking</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.sleep-wake">
    <description>Put NetworkManager to sleep or wake it up (should  only be used by system power management)</description>
    <message>System policy prevents putting NetworkManager to sleep or waking it up</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>no</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.enable-disable-wifi">
    <description>Enable or disable WiFi devices</description>
    <message>System policy prevents enabling or disabling WiFi devices</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.enable-disable-wwan">
    <description>Enable or disable mobile broadband devices</description>
    <message>System policy prevents enabling or disabling mobile broadband devices</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.enable-disable-wimax">
    <description>Enable or disable WiMAX mobile broadband devices</description>
    <message>System policy prevents enabling or disabling WiMAX mobile broadband devices</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.network-control">
    <description>Allow control of network connections</description>
    <message>System policy prevents control of network connections</message>
    <defaults>
      <allow_inactive>yes</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.wifi.share.protected">
    <description>Connection sharing via a protected WiFi network</description>
    <message>System policy prevents sharing connections via a protected WiFi network</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.wifi.share.open">
    <description>Connection sharing via an open WiFi network</description>
    <message>System policy prevents sharing connections via an open WiFi network</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.settings.modify.own">
    <description>Modify personal network connections</description>
    <message>System policy prevents modification of personal network settings</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.settings.modify.system">
    <description>Modify network connections for all users</description>
    <message>System policy prevents modification of network settings for all users</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>auth_admin_keep</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.settings.modify.hostname">
    <description>Modify persistent system hostname</description>
    <message>System policy prevents modification of the persistent system hostname</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>auth_admin_keep</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.use-user-connections">
    <description>Allow use of user-specific connections</description>
    <message>System policy prevents use of user-specific connections</message>
    <defaults>
      <allow_inactive>yes</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

</policyconfig>

and here’s openSUSE, with the different bits highlighted

sam@T440s:~$ cat /usr/share/polkit-1/actions/org.freedesktop.NetworkManager.policy | egrep -v '[description|message] xml'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
 "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
<policyconfig>

  <vendor>NetworkManager</vendor>
  <vendor_url>http://www.gnome.org/projects/NetworkManager</vendor_url>
  <icon_name>nm-icon</icon_name>

  <action id="org.freedesktop.NetworkManager.enable-disable-network">
    <description>Enable or disable system networking</description>
    <message>System policy prevents enabling or disabling system networking</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.sleep-wake">
    <description>Put NetworkManager to sleep or wake it up (should only be used by system power management)</description>
    <message>System policy prevents putting NetworkManager to sleep or waking it up</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>no</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.enable-disable-wifi">
    <description>Enable or disable WiFi devices</description>
    <message>System policy prevents enabling or disabling WiFi devices</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.enable-disable-wwan">
    <description>Enable or disable mobile broadband devices</description>
    <message>System policy prevents enabling or disabling mobile broadband devices</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.enable-disable-wimax">
    <description>Enable or disable WiMAX mobile broadband devices</description>
    <message>System policy prevents enabling or disabling WiMAX mobile broadband devices</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.network-control">
    <description>Allow control of network connections</description>
    <message>System policy prevents control of network connections</message>
    <defaults>
      **<allow_any>auth_admin</allow_any>**
      <allow_inactive>yes</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.wifi.share.protected">
    <description>Connection sharing via a protected WiFi network</description>
    <message>System policy prevents sharing connections via a protected WiFi network</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.wifi.share.open">
    <description>Connection sharing via an open WiFi network</description>
    <message>System policy prevents sharing connections via an open WiFi network</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.settings.modify.own">
    <description>Modify personal network connections</description>
    <message>System policy prevents modification of personal network settings</message>
    <defaults>
      **<allow_any>auth_self_keep</allow_any>
      <allow_inactive>yes</allow_inactive>**
      <allow_active>yes</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.settings.modify.system">
    <description>Modify network connections for all users</description>
    <message>System policy prevents modification of network settings for all users</message>
    <defaults>
      **<allow_any>auth_admin_keep</allow_any>
      <allow_inactive>auth_admin_keep</allow_inactive>**
      <allow_active>auth_admin_keep</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.NetworkManager.settings.modify.hostname">
    <description>Modify persistent system hostname</description>
    <message>System policy prevents modification of the persistent system hostname</message>
    <defaults>
      **<allow_any>auth_admin_keep</allow_any>
      <allow_inactive>auth_admin_keep</allow_inactive>**
      <allow_active>auth_admin_keep</allow_active>
    </defaults>
  </action>

</policyconfig>

It seems allow_inactive deals with remote sessions, allow_active is local sessions, and allow_any is both.

no denies authentication and yes grants it without prompting for a password.
auth_self requires a user password and auth_admin requires an administrator password, and the *_keep options result in authentication being granted for a period of time.

That explains why if I provide the root password when asked it will connect, and then if I disconnect and reconnect I don’t need the root password again.

Anyway, the setttings that matter seem to be the same on both systems (admin authentication is required to modify system connections, which I think is the action required to connect to wifi if it’s a system connection). I guess I could do something like this:


polkit.addRule(function(action, subject) {     if (action.id == "org.freedesktop.NetworkManager.settings.modify.system" &&
        subject.user == "sam") {
        return polkit.Result.YES;
    }
});

But I don’t really understand why it’s necessary in the first place - why does openSUSE connect without authentication when Ubuntu does not?

Is it a NetworkManager setting?

Hi
AFAIK, in the NetworkManager settings under Identity, check the box allow for all users, enter root password and all done (well that’s how it works in GNOME…).

That’s what I was expecting too (assuming “All users may connect to this network” is the KDE equivalent?)


Since changing that setting, I’ve rebooted several times and I’ve had to provide the root PW to connect each time :S

Well that’s strange… I just rebooted again and sure enough the password prompt came up for networkmanager, but when I clicked cancel instead of entering the password it connected straight away!

:sarcastic:

After a lot of fiddling around, I found a solution to my problem.

I still use restore session so kontact is running when I log in. Running kmail manually in autostart (not kontact) seems to kick the count into connecting.

I’ve tested it a few times without specifying a wait, and it seems to work OK.

One further thing that was bugging me was that kontact was being restored maximised each time I logged in, even though I normally use it minimised to the system tray.

I used QDBusViewer to investigate if there was a dbus method I could use to minimise it, and sure enough, I found one:

qdbus org.kde.kontact /kontact/MainWindow_1 hide

So my command in startup is now:

kmail && qdbus org.kde.kontact /kontact/MainWindow_1 hide

Which:

  • Gives Kmail the kick up the bum it needs to connect the account
  • Minimises Kontact when I log in :slight_smile:

As for the wifi thing, I found that the fastest way to connect was to uncheck “All users may connect to this network” and remove the password from kwallet - neither of the other two methods would work without requiring a password (either for kwallet, or for root).

Thank you again to everyone who has made helpful suggestions :slight_smile: