Outlook load url when body changed - visual-studio

I am developing email tracking application in VSTO. It loads tracking url when tracking url assign in html body. My code sample in send button event as
private void Application_ItemSend(object Item, ref bool Cancel)
{
Outlook.MailItem mailItem = Item as Outlook.MailItem;
string body = mailItem.HTMLBody;
string imagurl = String.Format("<img id='shtracking' src='{0}' border='0'
width='0' height='0'>",emailTrack);
int index2 = body.IndexOf("</body>");
string finalResult = body.Insert(index2, imagurl);
mailItem.HTMLBody = finalResult; //issue
}
It reloads the page before sent message. Is anyway to block the request before sent email ?
Thanks

Try to cancel the submission (set the Cancel parameter to true) and start a timer - by the time it fires, you will be out of the Send event handler, so yo would be able to call MailItem.Close to close the inspector. You can then set the HTMLBody property and call Send again. Mark the item somehow to avoid processing it in the Send event again.

Related

outlook vsto sending mail

I've been struggling with this for a while now and I can't get an answer anywhere.
I made an outlook add in which has a ribbon and two buttons, The one button opens up a mailitem where you can compose your mail and then the 2nd button sends the mail.
In the background it takes all of the recipients and adds it to the bcc field and sends the mail in batches for instance if there are 100 recipients it will send to 25 people at time.
So my problem is that it works perfectly on the developer PC but the send button doesn't work on the end user PC. The add in loads registries are fine and it targets the right .Net framework everything!
private void CreateEmailItem(Outlook.Recipient strRecipientAddressTo)
{
string strFilePath = #"c:\temp\OutlookAttachments";
string[] strFiles = Directory.GetFiles(strFilePath);
bool bFileExists = Directory.Exists(strFilePath);
Outlook.MailItem eMail = (Outlook.MailItem)
Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.MailItem mailItem = Globals.ThisAddIn.Application.ActiveInspector().CurrentItem as Outlook.MailItem;
eMail.Subject = mailItem.Subject;
eMail.BCC = mailItem.To;
eMail.Body = mailItem.Body;
if (bFileExists)
{
foreach (string file in strFiles)
{
File.SetAttributes(file, FileAttributes.Normal);
eMail.Attachments.Add(file);
}
}
((Outlook._MailItem)eMail).Send();
}
When the send button on the ribbon is clicked this method is called, but on end user the button just doensn't fire .. can this be permissions ? or any advice would be very much appreciated !!!!
It is hard to suggest there but did you add any logging there. There can be chances that you are getting some crash in following line..
email.Attachments.Add(file)
And thats why it is not reaching until send statement. You can check the event logs on user's system as well. They might help you.

Raw Notification Handling in UI inside my App in Windows Phone 8

Can some one help me out in showing a TextBox in all screens after parsing a Raw Notification data. I'm successfully able to show this data on a MessageBox like the code below but unable to show in TextBox and I want this TextBox to be called from any screen in my app. How can I do this?
public void PushChannel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
{
string message;
using (System.IO.StreamReader reader = new System.IO.StreamReader(e.Notification.Body))
{
message = reader.ReadToEnd();
}
Debug.WriteLine("This is a "+message);
var RawNotification = (RawData)serializer.ReadObject(e.Notification.Body);*/
Dispatcher.BeginInvoke(() =>
MessageBox.Show(String.Format("Received Notification {0}:\n{1}",
DateTime.Now.ToShortTimeString(), message))
);
}
I did this for one of my app. I Don't know if this is correct way of doing it or not but it solved my purpose.
1) First Create a UserControl in whatever look and feel you want to have. Make sure you create a Public Variable that will accept String ( In this case your Message )
2) Create a method in App.xaml.cs with String parameter ( To Pass your message string ). Withing the Method, Do a Dispatcher which will call a Messagebox with Content as the usercontrol. When invoking the UserControl, Pass your message as parameter.
Now whenerver or wherever you want to display a message, Use this method from App.xaml.cs and then you can create this textbox update.

C++ builder indy intercept IdHTTPProxyServer to insert header

I want to insert header of external script over https inside browser. For those purpose i use C++ builder with IdHTTPProxyServer component. I read Document from Response event but dont know how to just insert one simple .js. -> cause Document property is read only, on the other side BeforeCommandHandler want append with script (in code under i use just text to insert for simplicity)
How to insert .js external script in C++ builder?
Here is what i done so far.
void __fastcall TForm5::IdHTTPProxyServer1HTTPResponse
(TIdHTTPProxyServerContext *AContext)
{
Memo1->Lines->Append("\nOn Response!!!\n" + AContext->Document);
}
void __fastcall TForm5::IdHTTPProxyServer1BeforeCommandHandler
(TIdCmdTCPServer *ASender, UnicodeString &AData, TIdContext *AContext) {
try {
Memo1->Lines->Add(AData);
UnicodeString sa = AData;
AData = L"<html>Something</html>" + sa;
}
catch (int e) {
MessageBeep(100);
}
}
The TIdHTTPProxyServer::OnBeforeCommandHandler event is triggered before a client's request is processed. The AData parameter is the original request. This event is meant for logging/altering commands before they are parsed.
The TIdHTTPProxyServer::OnHTTPBeforeCommand event is triggered after a client's request headers have been received but before a connection is established to the target server and the client's request body is read and sent to the server.
The TIdHTTPProxyServer::OnHTTPResponse event is triggered after a server's response headers have been received but before the response body is read and sent to the client.
So none of those events will help you.
Neither will the TIdHTTPProxyServerContext::Document property, for that matter. That property does not contain the document data, as you are assuming. It contains the server-relative URL of the document being requested instead.
To do what you are asking for, set the TIdHTTPProxyServer::DefaultTransferMode property to tmFullDocument and use the OnHTTPDocument event. The TIdHTTPProxyServerContext::TransferSource property will tell you if the data is coming from the client or the server.
You will have full access to the headers and body data and you can modify them as needed. Just make sure you update the TIdHTTPProxyServerContext.Headers, in particular the Content-Length header, if you modify the body data. The body data is provided as a TStream object (specifically, a TMemoryStream). So you can either modify the stream's content directly, or you can create a new TStream object with your desired content (the VStream parameter of the event is passed by reference so you can re-assign it).
For example:
void __fastcall TForm5::IdHTTPProxyServer1HTTPDocument(TIdHTTPProxyServerContext* AContext, TStream* &VStream)
{
if (AContext->TransferSource == tsServer)
{
String s = ReadStringAsContentType(VStream, AContext->Headers->Values[L"Content-Type"], QuoteHTTP);
// this is NOT thread-safe! TIdHTTPProxyServer is multi-threaded,
// you must synchronize with the main thread in order to safely
// update UI controls...
//
// Memo1->Text = s;
s = L"<html>Something</html>" + s;
delete VStream;
VStream = new TStringStream(s, Sysutils::TEncoding::UTF8);
AContext->Headers->Values[L"Content-Length"] = VStream->Size;
AContext->Headers->Params[L"Content-Type"][L"charset"] = L"utf-8";
}
}

Issue with SentOnBehalfOfName

i'm stack with Outlook issue where i want to change Email Sender. I want to send all emails from Outlook with one sender. When i change sender from Outlook it works fine but when i change it from Outlook plugin it's not work. I'm using following code:
private void adxOutlookEvents_ItemSend(object sender, ADXOlItemSendEventArgs e)
{
if (e.Item is MailItem)
{
MailItem mail = e.Item as MailItem;
mail.SentOnBehalfOfName = "UserName";
mail.Save();
return;
}
}
But nothing happens. I don't see any error or exception but email come to Outlook with old sender. Can you please help me with that?
UPDATED: The way how i fix it. We cant use property "SentOnBehalfOfName" Outlook handle it incorect. Except it you should use "Sender" property:
mail.Recipients.Add(mail.SentOnBehalfOfName);
mail.Recipients.ResolveAll();
var adressEntry = mail.Recipients[mail.Recipients.Count].AddressEntry;
mail.Recipients.Remove(mail.Recipients.Count);
mail.Sender = adressEntry;
Are you sending through Exchange and want to send on behalf of another user (do you have the permission?) or trying to send through a particular POP3/SMTP account (use MailItem.SendUsingAccount property)?

Using Redemption to reply to a mail only intermittently sets the body text

I'm using the below method to reply to mails coming in to a business function mailbox.
The body text being added is only intermittently being set. This method is only called when someone has emailed in to unsubscribe from a mailing but the email address of the sender (or in the body) hasn't been found in the database and we want to ask them to send us the mail address they want to unsubscribe.
private void replyToMail(OutlookItem item)
{
RDOSession session = new RDOSession();
session.Logon(null, null, null, true, null, null);
RDOMail thisItem = session.GetMessageFromID(item.EntryID, item.StoreID, null);
RDOMail reply = thisItem.Reply();
RDOAddressEntry optingout = session.AddressBook.GAL.ResolveName("optingout");
//reply.Sender = optingout; this had no effect
reply.SentOnBehalfOf = optingout;
reply.Subject = "Automated Response - Could not complete unsubscribe";
reply.Body = "This is an automated response from the Newsletter unsubscribe system. We couldn't find "+item.Sender+" in our database to unsubscribe you from our mailings.\r\n\r\nPlease reply to this mail and include the email address you want to unsubscribe.\r\n\r\nKind Regards\r\n.";
reply.Send();
session.Logoff();
}
Firstly, if you are already usign OOM, there is no reason to call RDOSession.Logon. You can simply ste the MAPIOBJECT property:
Replace the line session.Logon() with
session.MAPIOBJECT = item.Application.Session.MAPIOBJECT
do not call Logoff.
Secondly, do yo umean the message is received with out a body? Do you see teh empty bofy in the Sent Items folder?
I had to edit thingie.HTMLBody as well as thingie.Body.
I suppose I could have figured out how to tell when to set the value of each one but since I just want to be sure that I have control of the body in this instance I'm simply setting both.

Resources