src/eric7/EricNetwork/EricGoogleMail.py

Wed, 13 Jul 2022 14:55:47 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 13 Jul 2022 14:55:47 +0200
branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9245
6ee1705a1cb9
permissions
-rw-r--r--

Reformatted the source code using the 'Black' utility.

5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
3 # Copyright (c) 2017 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to send bug reports.
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import base64
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
12 import json
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
13 import datetime
8243
cc717c2ae956 Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
14 import contextlib
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from googleapiclient import discovery
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
17 from google.oauth2.credentials import Credentials
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
18 from requests_oauthlib import OAuth2Session
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
20 from PyQt6.QtCore import pyqtSlot, pyqtSignal, QObject, QUrl, QUrlQuery
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
21 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
22
8358
144a6b854f70 Sorted the eric specific extensions into packages named like the corresponding PyQt packages (i.e. EricCore,EricGui and EricWidgets).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8356
diff changeset
23 from EricWidgets.EricTextInputDialog import EricTextInputDialog
6559
1265efa7364f Some fixes for configuration pages.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
24
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 import Globals
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
27 from .EricGoogleMailHelpers import (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
28 CLIENT_SECRET_FILE,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
29 SCOPES,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
30 TOKEN_FILE,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
31 APPLICATION_NAME,
7253
50dbe65a1334 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
32 )
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
35 class EricGoogleMailAuthBrowser(QDialog):
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
37 Class implementing a simple web browser to perform the OAuth2
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
38 authentication process.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
39
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
40 @signal approvalCodeReceived(str) emitted to indicate the receipt of the
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
41 approval code
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
43
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
44 approvalCodeReceived = pyqtSignal(str)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
45
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
46 def __init__(self, parent=None):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
47 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
48 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
49
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
50 @param parent reference to the parent widget
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
51 @type QWidget
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
52 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
53 super().__init__(parent)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
54
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
55 self.__layout = QVBoxLayout(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
56
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
57 from PyQt6.QtWebEngineWidgets import QWebEngineView
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
58
7196
ab0a91b82b37 Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
59 self.__browser = QWebEngineView(self)
ab0a91b82b37 Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
60 self.__browser.titleChanged.connect(self.__titleChanged)
ab0a91b82b37 Removed support for QtWebKit and the old web rowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
61 self.__browser.loadFinished.connect(self.__pageLoadFinished)
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
62 self.__layout.addWidget(self.__browser)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
63
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
64 self.__buttonBox = QDialogButtonBox(QDialogButtonBox.StandardButton.Close)
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
65 self.__buttonBox.rejected.connect(self.reject)
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
66 self.__layout.addWidget(self.__buttonBox)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
67
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
68 self.resize(600, 700)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
69
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
70 @pyqtSlot(str)
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
71 def __titleChanged(self, title):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
72 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
73 Private slot handling changes of the web page title.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
74
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
75 @param title web page title
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
76 @type str
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
77 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
78 self.setWindowTitle(title)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
79
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
80 @pyqtSlot()
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
81 def __pageLoadFinished(self):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
82 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
83 Private slot handling the loadFinished signal.
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
84 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
85 url = self.__browser.url()
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
86 if url.toString().startswith(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
87 "https://accounts.google.com/o/oauth2/approval/v2"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
88 ):
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7196
diff changeset
89 urlQuery = QUrlQuery(url)
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7196
diff changeset
90 approvalCode = urlQuery.queryItemValue(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
91 "approvalCode", QUrl.ComponentFormattingOption.FullyDecoded
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
92 )
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
93 if approvalCode:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
94 self.approvalCodeReceived.emit(approvalCode)
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
95 self.close()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
96
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
97 def load(self, url):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
98 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
99 Public method to start the authorization flow by loading the given URL.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
100
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
101 @param url URL to be laoded
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
102 @type str or QUrl
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
103 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
104 self.__browser.setUrl(QUrl(url))
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
107 class EricGoogleMail(QObject):
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
109 Class implementing the logic to send emails via Google Mail.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
110
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
111 @signal sendResult(bool, str) emitted to indicate the transmission result
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
112 and a result message
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
114
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
115 sendResult = pyqtSignal(bool, str)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
116
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
117 def __init__(self, parent=None):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
118 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
119 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
120
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
121 @param parent reference to the parent object
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
122 @type QObject
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
123 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
124 super().__init__(parent=parent)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
125
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
126 self.__messages = []
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
127
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
128 self.__session = None
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
129 self.__clientConfig = {}
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
130
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
131 self.__browser = None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
132
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
133 def sendMessage(self, message):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
134 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
135 Public method to send a message via Google Mail.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
136
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
137 @param message email message to be sent
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
138 @type email.mime.text.MIMEBase
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
139 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
140 self.__messages.append(message)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
141
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
142 if not self.__session:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
143 self.__startSession()
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
144 else:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
145 self.__doSendMessages()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
146
7192
a22eee00b052 Started removing runtime support for Python2 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
147 def __prepareMessage(self, message):
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
148 """
7199
c71bd6f21748 Removed some more Python2 stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7198
diff changeset
149 Private method to prepare the message for sending.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
150
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
151 @param message message to be prepared
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
152 @type email.mime.text.MIMEBase
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
153 @return prepared message dictionary
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
154 @rtype dict
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
155 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
156 messageAsBase64 = base64.urlsafe_b64encode(message.as_bytes())
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
157 raw = messageAsBase64.decode()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
158 return {"raw": raw}
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
159
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
160 def __startSession(self):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
161 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
162 Private method to start an authorized session and optionally start the
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
163 authorization flow.
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
164 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
165 # check for availability of secrets file
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
166 if not os.path.exists(os.path.join(Globals.getConfigDir(), CLIENT_SECRET_FILE)):
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
167 self.sendResult.emit(
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
168 False,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
169 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
170 "The client secrets file is not present. Has the Gmail"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
171 " API been enabled?"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
172 ),
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
173 )
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
174 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
175
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
176 with open(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
177 os.path.join(Globals.getConfigDir(), CLIENT_SECRET_FILE), "r"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
178 ) as clientSecret:
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
179 clientData = json.load(clientSecret)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
180 self.__clientConfig = clientData["installed"]
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
181 token = self.__loadToken()
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
182 if token is None:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
183 # no valid OAuth2 token available
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
184 self.__session = OAuth2Session(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
185 self.__clientConfig["client_id"],
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
186 scope=SCOPES,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
187 redirect_uri=self.__clientConfig["redirect_uris"][0],
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
188 )
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
189 authorizationUrl, _ = self.__session.authorization_url(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
190 self.__clientConfig["auth_uri"],
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
191 access_type="offline",
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
192 prompt="select_account",
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
193 )
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
194 if self.__browser is None:
8243
cc717c2ae956 Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
195 with contextlib.suppress(ImportError):
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
196 self.__browser = EricGoogleMailAuthBrowser()
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
197 self.__browser.approvalCodeReceived.connect(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
198 self.__processAuthorization
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
199 )
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
200 if self.__browser:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
201 self.__browser.show()
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
202 self.__browser.load(QUrl(authorizationUrl))
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
203 else:
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
204 from PyQt6.QtGui import QDesktopServices
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
205
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
206 QDesktopServices.openUrl(QUrl(authorizationUrl))
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8354
diff changeset
207 ok, authCode = EricTextInputDialog.getText(
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
208 None,
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
209 self.tr("OAuth2 Authorization Code"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
210 self.tr("Enter the OAuth2 authorization code:"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
211 )
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
212 if ok and authCode:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
213 self.__processAuthorization(authCode)
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
214 else:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
215 self.__session = None
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 else:
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
217 self.__session = OAuth2Session(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
218 self.__clientConfig["client_id"],
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
219 scope=SCOPES,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
220 redirect_uri=self.__clientConfig["redirect_uris"][0],
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
221 token=token,
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
222 auto_refresh_kwargs={
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
223 "client_id": self.__clientConfig["client_id"],
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
224 "client_secret": self.__clientConfig["client_secret"],
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
225 },
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
226 auto_refresh_url=self.__clientConfig["token_uri"],
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
227 token_updater=self.__saveToken,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
228 )
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
229 self.__doSendMessages()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
230
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
231 @pyqtSlot(str)
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
232 def __processAuthorization(self, authCode):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
233 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
234 Private slot to process the received authorization code.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
235
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
236 @param authCode received authorization code
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
237 @type str
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
238 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
239 self.__session.fetch_token(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
240 self.__clientConfig["token_uri"],
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
241 client_secret=self.__clientConfig["client_secret"],
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
242 code=authCode,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
243 )
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
244 self.__saveToken(self.__session.token)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
245
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
246 # authorization completed; now send all queued messages
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
247 self.__doSendMessages()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
248
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
249 def __doSendMessages(self):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
250 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
251 Private method to send all queued messages.
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
252 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
253 if not self.__session:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
254 self.sendResult.emit(False, self.tr("No authorized session available."))
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
255 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
256
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
257 try:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
258 results = []
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
259 credentials = self.__credentialsFromSession()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
260 service = discovery.build(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
261 "gmail", "v1", credentials=credentials, cache_discovery=False
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
262 )
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
263 count = 0
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
264 while self.__messages:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
265 count += 1
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
266 message = self.__messages.pop(0)
7192
a22eee00b052 Started removing runtime support for Python2 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
267 message1 = self.__prepareMessage(message)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
268 service.users().messages().send(userId="me", body=message1).execute()
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
269 results.append(self.tr("Message #{0} sent.").format(count))
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
271 self.sendResult.emit(True, "\n\n".join(results))
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
272 except Exception as error:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
273 self.sendResult.emit(False, str(error))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
274
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
275 def __loadToken(self):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
276 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
277 Private method to load a token from the token file.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
278
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
279 @return loaded token
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
280 @rtype dict or None
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
281 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
282 homeDir = os.path.expanduser("~")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
283 credentialsDir = os.path.join(homeDir, ".credentials")
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
284 if not os.path.exists(credentialsDir):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
285 os.makedirs(credentialsDir)
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
286 tokenPath = os.path.join(credentialsDir, TOKEN_FILE)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
287
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
288 if os.path.exists(tokenPath):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
289 with open(tokenPath, "r") as tokenFile:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
290 return json.load(tokenFile)
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
291 else:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
292 return None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
293
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
294 def __saveToken(self, token):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
295 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
296 Private method to save a token to the token file.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
297
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
298 @param token token to be saved
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
299 @type dict
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
300 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
301 homeDir = os.path.expanduser("~")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
302 credentialsDir = os.path.join(homeDir, ".credentials")
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
303 if not os.path.exists(credentialsDir):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
304 os.makedirs(credentialsDir)
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
305 tokenPath = os.path.join(credentialsDir, TOKEN_FILE)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
306
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
307 with open(tokenPath, "w") as tokenFile:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
308 json.dump(token, tokenFile)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
309
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
310 def __credentialsFromSession(self):
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
311 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
312 Private method to create a credentials object.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
313
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
314 @return created credentials object
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
315 @rtype google.oauth2.credentials.Credentials
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
316 """
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
317 credentials = None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
318
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
319 if self.__clientConfig and self.__session:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
320 token = self.__session.token
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
321 if token:
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
322 credentials = Credentials(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
323 token["access_token"],
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
324 refresh_token=token.get("refresh_token"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
325 id_token=token.get("id_token"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
326 token_uri=self.__clientConfig["token_uri"],
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
327 client_id=self.__clientConfig["client_id"],
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
328 client_secret=self.__clientConfig["client_secret"],
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
329 scopes=SCOPES,
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
330 )
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
331 credentials.expiry = datetime.datetime.fromtimestamp(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
332 token["expires_at"]
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
333 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
334
6828
bb6667ea9ae7 Changed the Google Mail interface to not use obsoleted packages anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6825
diff changeset
335 return credentials
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 def GoogleMailHelp():
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 """
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 Module function to get some help about how to enable the Google Mail
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 OAuth2 service.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
342
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 @return help text
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 @rtype str
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 """
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 return (
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 "<h2>Steps to turn on the Gmail API</h2>"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 "<ol>"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 "<li>Use <a href='{0}'>this wizard</a> to create or select a project"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 " in the Google Developers Console and automatically turn on the API."
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 " Click <b>Continue</b>, then <b>Go to credentials</b>.</li>"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 "<li>At the top of the page, select the <b>OAuth consent screen</b>"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 " tab. Select an <b>Email address</b>, enter a <b>Product name</b> if"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 " not already set, and click the <b>Save</b> button.</li>"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 "<li>Select the <b>Credentials</b> tab, click the <b>Add credentials"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 "</b> button and select <b>OAuth 2.0 client ID</b>.</li>"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 "<li>Select the application type <b>Other</b>, enter the name &quot;"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 "{1}&quot;, and click the <b>Create</b>"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 " button.</li>"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 "<li>Click <b>OK</b> to dismiss the resulting dialog.</li>"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 "<li>Click the (Download JSON) button to the right of the client ID."
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 "</li>"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 "<li>Move this file to the eric configuration directory"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 " <code>{2}</code> and rename it <code>{3}</code>.</li>"
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 "</ol>".format(
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 "https://console.developers.google.com/start/api?id=gmail",
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 APPLICATION_NAME,
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 Globals.getConfigDir(),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
369 CLIENT_SECRET_FILE,
5769
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 )
944c04cec861 Added the capability to send these emails via Google Mail using OAuth2 authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 )

eric ide

mercurial