Embedded graphics in original mail change to attached graphics in reply when using exchangelib in python - exchangelib

We have a python script that replies to incoming emails using exchangelib. User A sends us an email that can contain a picture/graphic (e.g. company logo in signature line). Our script is able to reply to his mail, and user A will get our reply. Unfortunately, the picture/graphic that was embedded in the original mail to us, is now an attached file instead of an embedded picture.
Here is the code that we're using:
origmsg.reply(
subject='Re: ' + origmsg.subject,
body="This is my reply to your inquiry...."
)
I understand that for new messages the HTML code needs to include a reference to the attached file to make it embedded. How can this be done in a reply?
Thanks.

https://ecederstrand.github.io/exchangelib/#attachments has some example of embedding images in emails.
The .reply() method is for simple replies. You may need to call .create_reply() instead and edit the returned ReplyToItem object as needed before calling .send() on it.
If you have even more special requirements, you can call .save() on the ReplyToItem object to save it as a draft, fetch the draft as a plain Message object with account.drafts.get(id=reply_to_item_id) and do whatever you need to do before sending the draft.

Related

How to ALTER CHANNEL in C++?

IBM's documentation on ALTER CHANNEL goes to commendable length explaining the various available alterations, but does not offer a single example -- certainly not for C++-users.
Suppose, I want to change the MCAUSER from the default (OS username) to another string, what would the function-call look like?
The documentation you link to in your question is the MQSC command reference. This is designed for scripts.
Please also note that the default value of a channel's MCAUSER field is actually blank, not the OS username. Because it is blank, then in the case of a SVRCONN channel, when a client application connects, the OS username flowed from the client, will be used for the MCAUSER for that running instance. You cannot change this behaviour using ALTER CHANNEL from your client application. I note this, in case this is the reason you are thinking to use ALTER CHANNEL.
If you want to write a program to make a change to an IBM MQ object, such as a channel, you would instead want to make use of a different, but equivalent interface called the Programmable Command Format (PCF). The equivalent command reference page is here.
There is an example C++ PCF sample here - look for SrvPCF
In short, psuedo-code, you would write a program as follows:-
MQCONN(Qmgr-name)
MQOPEN(Reply-Q)
Build PCF message for MQCMD_CHANGE_CHANNEL
with MQCACH_CHANNEL_NAME
with MQIACH_CHANNEL_TYPE
with MQCACH_MCA_USER_ID
MQPUT1(PCF Message to SYSTEM.ADMIN.COMMAND.QUEUE)
MQGET(wait for reply on Reply-Q to say whether it worked or not)

How can I add a new message in the mavlink protocol?

I'm new in Mavlink, I want to add a new message in the Mavlink protocol and send it each second periodically. How can I do it?
Here you can find detailed steps about how to add new message to mavlink protocol and how you handle it.
Ensure you have the latest ArduPilot code and Mavproxy installed.
Decide what type of message you want to add.
Add the new message definition to the common.xml or ardupilotmega.xml file in the mavlink submodule.
Add functions to the main vehicle code to handle sending or receiving the command.
It depends on what autopilot you are using. If you're using ardupilot then you would need to add a new xml message definition in ardupilot/modules/mavlink/message_definitions/v1.0/ardupilotmega.xml.
You can look at the other messages to see how it should be formatted. Just make sure you choose an id that is unused.
Next you need to decide how to put this in the code. You could place it in the data_stream_send task by adding the message id to, say, STREAM_EXTRA3. This will send your message as often as the other data is sent there. As part of that you will need to define the function to actually pack your data structure using the function generated by pymavgen, the message id and enumerations. This is what I have done in my own project for ASH_DATA. You can see the changes I've made in my repository for reference. Note that some of those include changes to incorporate reception of ash data on the pixhawk and adding the data to a log file.
Given that you want to run this once a second you may want to add to the one_second_loop task or create your own task that simply calls the try_send_message function using your new message id.
You will of course need to incorporate the new message in your gcs so you can actually receive it, but that's another matter.
Hopefully this can nudge others in the right direction who are trying to do the same.

Django - Send Output Continually

I want to start processing some files from a django view and I want to be able to send the name of the files to the browser as they are processed. Is there a way to do this (easily)? I could probably do this using threads and ajax calls, but I want the simplest solution for now.
I found what I needed in an answer from one of the links that Andre Miller provided.
I found out that's possible to pass an iterator to HttpResponse so I used this code and it worked:
def import_iter():
""" Used to return output as it is generated """
# First return the template
t = loader.get_template('main/qimport.htm')
c = Context()
yield t.render(c)
# Now process the files
if req.method == 'POST':
location = req.POST['location']
if location:
for finfo in import_location(location):
yield finfo+"<br/>"
return HttpResponse(import_iter())
You would need to use some sort of queuing process if you want to kick off the task when the view is rendered, otherwise the process will finish first before anything is returned to the browser.
Once the task is running asynchronously you could use either AJAX to update the page with the latest status or simply use a meta-refresh inside the page to load the new content.
There is Django queue server here you could use:
http://code.google.com/p/django-queue-service/
It would seem that this question has also been asked a few times before:
How to best launch an asynchronous job request in Django view?
Is there any way to make an asynchronous function call from Python [Django]?
How do you do something after you render the view? (Django)
We are in 201X
Yes, you should use WebSockets or Ajax calls !!
Since you were asking(for the record purpose) for some streaming solution in Django you can use StreamingHttpResponse which Django supports out of the box.
https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.StreamingHttpResponse
The StreamingHttpResponse class is used to stream a response from Django to the browser. You might want to do this if generating the response takes too long or uses too much memory. For instance, it’s useful for generating large CSV files.
If you clear the output buffer, then you should be able to see what has been processed.
First of all, make sure you output a Connection: Keep-Alive header, after which you just have to make sure that the script output isn't being buffered. In Python, you can use the cgi module's cgiprint function to ensure that Python's buffer is cleared, but you should also check the web server configuration, as some will buffer all output until the script finishes running.

how to upload file by POST in libcurl?

how to upload file by POST in libcurl?(c++)
Are you referring to RFC 1867 (i.e., what the browser sends when the user submits an HTML form containing an input field with type="file")?
If that's the case, you may be interested in http://curl.haxx.se/libcurl/c/postit2.html
From the documentation here:
When using libcurl's "easy" interface you init your session and get a handle (often referred to as an "easy handle"), which you use as input to the easy interface functions you use. Use curl_easy_init to get the handle.
You continue by setting all the options you want in the upcoming transfer, the most important among them is the URL itself (you can't transfer anything without a specified URL as you may have figured out yourself). You might want to set some callbacks as well that will be called from the library when data is available etc. curl_easy_setopt is used for all this.
When all is setup, you tell libcurl to perform the transfer using curl_easy_perform. It will then do the entire operation and won't return until it is done (successfully or not).
After the transfer has been made, you can set new options and make another transfer, or if you're done, cleanup the session by calling curl_easy_cleanup. If you want persistent connections, you don't cleanup immediately, but instead run ahead and perform other transfers using the same easy handle.
So it looks like you need to call the following:
curl_easy_init (initialize the curl session)
curl_easy_setopt (setup the session options)
curl_easy_perform (perform the curl)
curl_easy_cleanup (delete the session)
Given that these are C APIs you should have no problem calling them within a C++ source file.

How do you configure the email settings in CrashRpt to send the crash dump?

After reading this discussion and this discussion about using CrashRpt to generate a crash dump and email it to the developers, I've been having a difficult time finding any instructions/tutorials for configuring the email settings used by the library to send the email.
When you call the install() function to initialize CrashRpt, you specify the email address you want the crash dump sent to, but how does the CrashPrt library know how to send the email to that address? Wouldn't the library have to know the email client settings for each individual user?
When a fatal crash occurs in my code, the CrashRpt dialog box pops up and when I enter my email address and click the send button, it takes me to a "Save File" dialog box where I can save the zipped package and the account specified in the Install() function never receives an email.
Thanks in advance for any and all help! I'm clearly missing something.
What CrashRpt does for emailing:
The email system simply uses MAPI to send your email. Which would try to use your default mail client if you have one, and if it supports MAPI. Take a look at MailMsg.cpp for details.
Personal experience:
In my company's usage of CrashRpt, we modified it a bit though to call a web service that we created which submits the crash report. So we gutted the emailing code completely from CrashRpt. And instead we have in our bug tracking system a section for crashes that were auto submitted when crashes happen.
To find your problem:
I would maybe try to debug the CrashRpt code to see why it's giving you a save dialog. It should instead just open your default mail client. Maybe you have an older version of the library, or maybe the dialog resources are a little messed. Debugging the code will tell you this though.
Most likely MailReport is being called but is failing.
Set a breakpoint in the original CrashRpt code's CrashHandler.cpp at just after the DoModal:
mainDlg.m_pUDFiles = &m_files;
if (IDOK == mainDlg.DoModal())
{
//Put breakpoint here <---------
if (m_sTo.IsEmpty() ||
!MailReport(rpt, sTempFileName, mainDlg.m_sEmail, mainDlg.m_sDescription))
{
SaveReport(rpt, sTempFileName);
}
}
Check to see why MailReport is not getting called. It's either the dialog resource, or your m_sTo is not filled or you can step through MailMsg.cpp and see where MAPI is failing.
Alternate solution:
An easy fix, if you find above that MailReport is being called, but not succeeding, is to instead just do a ShellExecute and specify a mailto:
You could even try to use the MAPI method, but if that fails to do a mailto:
You can find the CrashRpt documentation, FAQ and download a new CrashRpt v1.1 here http://code.google.com/p/crashrpt/