Skip to content

Commit

Permalink
feat: select 'from mailbox' while sending mail
Browse files Browse the repository at this point in the history
  • Loading branch information
krantheman committed Nov 21, 2024
1 parent 44dd6ab commit 8a00f4f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
20 changes: 19 additions & 1 deletion frontend/src/components/Modals/SendMail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
<template #top>
<div class="flex flex-col gap-3">
<div class="flex items-center gap-2 border-t pt-2.5">
<span class="text-xs text-gray-500">{{ __('From') }}:</span>
<Link
v-model="mail.from"
doctype="Mailbox"
:filters="{ user: user.data.name }"
/>
</div>
<div class="flex items-center gap-2">
<span class="text-xs text-gray-500">{{ __('To') }}:</span>
<MultiselectInput
class="flex-1 text-sm"
Expand Down Expand Up @@ -151,6 +159,7 @@ import {
} from 'frappe-ui'
import { reactive, watch, inject, ref, nextTick, computed } from 'vue'
import { Paperclip, Laugh } from 'lucide-vue-next'
import Link from '@/components/Controls/Link.vue'
import EmojiPicker from '@/components/EmojiPicker.vue'
import MultiselectInput from '@/components/Controls/MultiselectInput.vue'
import { EditorContent } from '@tiptap/vue-3'
Expand Down Expand Up @@ -178,6 +187,7 @@ const props = defineProps({
})
const mail = reactive({
from: '',
to: '',
cc: '',
bcc: '',
Expand All @@ -199,12 +209,20 @@ watch(show, () => {
}
})
const defaultOutgoing = createResource({
url: 'mail_client.api.mail.get_default_outgoing',
auto: true,
onSuccess(data) {
mail.from = data
},
})
const sendMail = createResource({
url: 'mail_client.api.outbound.send',
method: 'POST',
makeParams(values) {
return {
from_: `${user.data?.full_name} <${user.data?.name}>`,
from_: `${user.data?.full_name} <${mail.from}>`,
...mail,
}
},
Expand Down
25 changes: 19 additions & 6 deletions mail_client/api/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ def get_translations() -> dict:
def get_incoming_mails(start: int = 0) -> list:
"""Returns incoming mails for the current user."""

mailboxes = frappe.get_all("Mailbox", {"user": frappe.session.user}, pluck="name")

mails = frappe.get_all(
"Incoming Mail",
{"receiver": frappe.session.user, "docstatus": 1},
{"receiver": ["in", mailboxes], "docstatus": 1},
[
"name",
"sender",
Expand Down Expand Up @@ -92,11 +94,7 @@ def get_outgoing_mails(start: int = 0) -> list:

mails = frappe.get_all(
"Outgoing Mail",
{
"sender": ["in", mailboxes],
"docstatus": 1,
"folder": "Sent",
},
{"sender": ["in", mailboxes], "docstatus": 1, "folder": "Sent"},
[
"name",
"subject",
Expand All @@ -113,6 +111,7 @@ def get_outgoing_mails(start: int = 0) -> list:
start=start,
order_by="created_at desc",
)

return get_mail_list(mails, "Outgoing Mail")


Expand Down Expand Up @@ -358,3 +357,17 @@ def get_mail_contacts(txt=None) -> list:
contact.update(details)

return contacts


@frappe.whitelist()
def get_default_outgoing() -> str:
"""Returns default outgoing mailbox."""

return frappe.get_all(
"Mailbox",
{
"user": frappe.session.user,
"is_default": 1,
},
pluck="name",
)[0]

0 comments on commit 8a00f4f

Please sign in to comment.