Skip to content

Commit d2ac4de

Browse files
committed
remove legacy Sengrid code
1 parent 217de9c commit d2ac4de

File tree

7 files changed

+2
-177
lines changed

7 files changed

+2
-177
lines changed

.env.example

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# Email Configuration
2-
SENDGRID_API_KEY=
3-
SENDGRID_FROM_EMAIL=
42
MS_FROM_EMAIL=[email protected]
53
EMAIL_SERVICE_TYPE=ms_graph
64

docs/email_digest_delivery_methods.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@ This document summarizes all the methods we have tried (and considered) for send
4747

4848
---
4949

50-
## 4. SendGrid or Third-Party SMTP Relay
51-
52-
- **Approach:** Use a third-party SMTP service (e.g., SendGrid) to send as the service account.
53-
- **Status:** **Not attempted** (would require IT approval and setup).
54-
- **Blocker:**
55-
- May not be allowed by organizational policy.
56-
5750
---
5851

5952
## 5. Distribution List/Group Delivery
@@ -75,7 +68,6 @@ This document summarizes all the methods we have tried (and considered) for send
7568
| MS Graph (App perms) | Yes | Blocked | Need admin to grant permissions |
7669
| MS Graph (Delegated) | No | Works (manual only) | Not suitable for automation |
7770
| SMTP (O365) | Yes | Blocked | SMTP AUTH disabled for tenant |
78-
| SendGrid/3rd-party | Yes | Not attempted | Needs IT approval |
7971
| Distribution List | Yes | Ready | Blocked by above sending method |
8072

8173
---

docs/email_system.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ The email system consists of the following components:
1212
- `EmailServiceBase`: Abstract base class defining the interface for all email services
1313
- `MSGraphEmailService`: Implementation using Microsoft Graph API with enterprise application authentication
1414
- `UserAuthEmailService`: Implementation using Azure CLI authentication
15-
- `SendGridEmailService`: Alternative implementation using SendGrid
1615
- `EmailFactory`: Factory pattern for creating the appropriate service based on configuration
1716

1817
2. **Weekly Digest Feature**
@@ -35,7 +34,7 @@ The email system consists of the following components:
3534
source venv/bin/activate
3635

3736
# Install the required packages
38-
pip install python-dotenv msgraph-core azure-identity httpx sendgrid
37+
pip install python-dotenv msgraph-core azure-identity httpx
3938
```
4039

4140
### Environment Variables
@@ -45,7 +44,7 @@ The following environment variables need to be set in your `.env.local` file:
4544
```
4645
# Email Configuration
4746
[email protected] # Email that will appear as the sender
48-
EMAIL_SERVICE_TYPE=ms_graph # Authentication type (ms_graph, user_auth, or sendgrid)
47+
EMAIL_SERVICE_TYPE=ms_graph # Authentication type (ms_graph or user_auth)
4948
5049
# Azure Authentication for UNDP Enterprise Application
5150
TENANT_ID=b3e5db5e-2944-4837-99f5-7488ace54319 # UNDP tenant ID
@@ -78,13 +77,6 @@ Requirements:
7877
- Azure CLI installed and logged in with `az login`
7978
- User must have Mail.Send permissions in Microsoft Graph
8079

81-
#### 3. SendGrid Authentication
82-
83-
Alternative email provider if Microsoft Graph is not available.
84-
85-
Requirements:
86-
- SendGrid API key
87-
- SendGrid from email address
8880

8981
### Azure AD Enterprise Application Configuration
9082

scripts/email_requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/services/email_factory.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88

99
from .email_service import EmailServiceBase
1010
from .msgraph_service import MSGraphEmailService
11-
from .sendgrid_service import SendGridEmailService
1211
from .user_auth_service import UserAuthEmailService
1312

1413
logger = logging.getLogger(__name__)
1514

1615
# Email service types
1716
MS_GRAPH = "ms_graph"
18-
SENDGRID = "sendgrid"
1917
USER_AUTH = "user_auth"
2018

2119
# Default to USER_AUTH with Azure CLI authentication
@@ -35,8 +33,6 @@ def create_email_service(useUserAccessToken: bool = False) -> EmailServiceBase:
3533

3634
if service_type == MS_GRAPH:
3735
return MSGraphEmailService(useUserAccessToken=useUserAccessToken)
38-
elif service_type == SENDGRID:
39-
return SendGridEmailService()
4036
elif service_type == USER_AUTH:
4137
return UserAuthEmailService()
4238
else:

src/services/sendgrid_service.py

Lines changed: 0 additions & 107 deletions
This file was deleted.

tests/test_email.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from main import app
1212
from src.services.msgraph_service import MSGraphEmailService
13-
from src.services.sendgrid_service import SendGridEmailService
1413

1514
client = TestClient(app)
1615

@@ -24,15 +23,6 @@ def mock_msgraph_client():
2423
mock.return_value = mock_instance
2524
yield mock_instance
2625

27-
@pytest.fixture
28-
def mock_sendgrid_client():
29-
with patch('src.services.sendgrid_service.SendGridAPIClient') as mock:
30-
mock_instance = MagicMock()
31-
mock_response = MagicMock()
32-
mock_response.status_code = 202
33-
mock_instance.send = MagicMock(return_value=mock_response)
34-
mock.return_value = mock_instance
35-
yield mock_instance
3626

3727
@pytest.mark.asyncio
3828
async def test_msgraph_send_email(mock_msgraph_client):
@@ -73,40 +63,7 @@ async def test_msgraph_send_notification(mock_msgraph_client):
7363
call_args = mock_msgraph_client.post.call_args[0]
7464
assert call_args[0] == "/me/sendMail"
7565

76-
@pytest.mark.asyncio
77-
async def test_sendgrid_send_email(mock_sendgrid_client):
78-
"""Test sending email via SendGrid"""
79-
# Setup
80-
service = SendGridEmailService()
81-
82-
# Test
83-
result = await service.send_email(
84-
to_emails=["[email protected]"],
85-
subject="Test Subject",
86-
content="Test Content"
87-
)
88-
89-
# Assert
90-
assert result is True
91-
mock_sendgrid_client.send.assert_called_once()
9266

93-
@pytest.mark.asyncio
94-
async def test_sendgrid_send_notification(mock_sendgrid_client):
95-
"""Test sending notification via SendGrid"""
96-
# Setup
97-
service = SendGridEmailService()
98-
99-
# Test
100-
result = await service.send_notification_email(
101-
to_email="[email protected]",
102-
subject="Test Notification",
103-
template_id="test-template",
104-
dynamic_data={"name": "Test User"}
105-
)
106-
107-
# Assert
108-
assert result is True
109-
mock_sendgrid_client.send.assert_called_once()
11067

11168
@pytest.mark.skip(reason="Requires database connection")
11269
def test_email_endpoints(headers: dict):

0 commit comments

Comments
 (0)