Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29762

Django : How to create , write and attach .ics file to mail with meeting response?

$
0
0

How can i create and attach .ics or .icalender file as an attachment in send_mail() function Django 1.11?

I have tried below code but failed:

from ics import Calendar, Event  

def send_mail_to_interviwee(request, round_pk):
    intv_round = Round.objects.get(pk=str(round_pk))
    supporters = list(intv_round.supporting_interviewer.values_list('email', flat=True))
    round_taker = intv_round.assignee

    subject = "Interview Scheduled..Please go through details"
    htmly = get_template('Evaluator/email_interview.html')
    d = {
        'round_taker': round_taker,
        'candidate': intv_round.interview.candidate,
         'round_date': intv_round.date,
         'round_name': intv_round.name,
         'round_time': intv_round.contact_time,
         'round_type': intv_round.round_type,
         'additional_Comments': intv_round.comments,

          }
    cal = Calendar()
    event = Event()
    event.name = intv_round.name
    event.begin = intv_round.date
    event.time_equals = intv_round.contact_time
    cal.events.add(event)
    file_name="interview.ics"
    with open(file_name,'w') as my_file:
        my_file.writelines(cal)


    html_content = htmly.render(d)
    all_mails = [round_taker.email] + supporters

    #Format: Subject, Message, from, to
    msg = EmailMultiAlternatives(subject, "Please find details of Candidate in this mail", request.user.email, all_mails)
    msg.attach(file_name)
    msg.attach_alternative(html_content, "text/html")

I am getting following error:

File "venv\lib\site-packages\ics\__init__.py", line 3, in <module>
from .alarm import AudioAlarm, DisplayAlarm
File "venv\lib\site-packages\ics\alarm\__init__.py", line 1, in <module>
from ics.alarm.audio import AudioAlarm
File "venv\lib\site-packages\ics\alarm\audio.py", line 25
trigger: Union[timedelta, datetime] = None,
       ^
enter code here

Viewing all articles
Browse latest Browse all 29762

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>