EWS: Find mail by EntryID/ItemID in sent items? - email

I have the EntryID and ItemID of a mail, how can I using EWS get the mail not knowing if it's in the "Inbox" or "Sent items"?
I've tried this..
Dim ewsID As String = "AAAAAMgC9AZo0nACt4jVCOhhCmcHAF35p973GUpBjIUVAx1CYigAAAAAABEAAF35p973GUpBjIUVAx1CYigAAiwdaBwAAA=="
Dim email As EmailMessage = EmailMessage.Bind(service, New Microsoft.Exchange.WebServices.Data.ItemId(ewsID))
But it doesn't find anything.
Help :)

If you have HexEntryId from PR_EntryId or from Outlook OOM app you need to use convertItem to convert to an EWSid to use eg based on what you posted this should work
String ItemId = "AAAAAMgC9AZo0nACt4jVCOhhCmcHAF35p973GUpBjIUVAx1CYigAAAAAABEAAF35p973GUpBjIUVAx1CYigAAiwdaBwAAA==";
AlternateId HexId = new AlternateId(IdFormat.HexEntryId, BitConverter.ToString(Convert.FromBase64String(ItemId)).Replace("-", ""), "Mailbo#domain.com");
AlternateIdBase Converted = service.ConvertId(HexId, IdFormat.EwsId);
EmailMessage Message = EmailMessage.Bind(service, new ItemId(((AlternateId)Converted).UniqueId));
Cheers
Glen

Related

Name email attachment in Google Apps Script

I have the following G.A.S script to email a google sheet as a pdf attachment.
var spreadsheet = SpreadsheetApp.getActive();
var subject = spreadsheet.getRange("U1:U1").getValues();
var emailTo = spreadsheet.getRange("V1:V1").getValues();
var message = spreadsheet.getRange("W1:W1").getValues();
var pdf = DriveApp.getFileById(spreadsheet.getId()).getAs('application/pdf').getBytes();
var attach = {fileName:subject,content:pdf, mimeType:'application/pdf'};
MailApp.sendEmail(emailTo, subject, message, {attachments:[attach]});
The above code works well except that the file attached to the email message has a bizarre name like "[Ljava.lang.Object_#4e63998c" with no ".pdf" extension!
I am looking for a way to set a name for the pdf file before being attached to the email. The file name should equal the "subject" variable.
Thanks in advance.
Omid
Values retrieved by getValues() is 2 dimensional array. I think that the filename becomes such string because the array is used as the filename. Please retrieve the element from the array and try again. So could you please modify as follows?
From :
var attach = {fileName:subject,content:pdf, mimeType:'application/pdf'};
To :
var attach = {fileName:subject[0][0],content:pdf, mimeType:'application/pdf'};
You can also use the following modification. In this case, getValue() can retrieve the value as a string from the cell "U1".
From :
var subject = spreadsheet.getRange("U1:U1").getValues();
To :
var subject = spreadsheet.getRange("U1:U1").getValue();
Reference :
getValue()
getValues()
If this was not what you want, please tell me. I would like to think of other solutions.
I'm a bit late, but another way to solve this problem might be:
var spreadsheet = SpreadsheetApp.getActive();
var subject = spreadsheet.getRange("U1:U1").getValues();
var emailTo = spreadsheet.getRange("V1:V1").getValues();
var message = spreadsheet.getRange("W1:W1").getValues();
var pdf = DriveApp.getFileById(spreadsheet.getId())
.getAs('application/pdf')
.getBlob()
.setName(subject);
MailApp.sendEmail(emailTo, subject, message, {attachments:[pdf]});
The Blob class has a setName method https://developers.google.com/apps-script/reference/base/blob#setName(String), that can be chained into a Blob object (which is the result of getBlob())
After that you just need to add the Blob object inside attachments array of function MailApp.sendEmail

Redemption in MS Access / Outlook (trying to include a separate message file in email)

This code is in MS Access (2010) VBA, using the Redemption library with Microsoft Outlook 2010.
I had this process working before, but we recently had a Citrix upgrade that I guess reset something in my Outlook and now the process no longer works.
I have a folder of .msg files which are basically pre-made email templates with all the proper formatting, images, text, etc.
This is what I was doing before:
Dim outlookApp As Object, namespace As Object
Dim oItem, MyItem
Set outlookApp = CreateObject("Outlook.Application")
Set namespace = outlookApp.GetNamespace("MAPI")
namespace.Logon
Set MyItem = outlookApp.CreateItemFromTemplate(path_to_dot_msg_file)
'And then there are many calls like this:
MyItem.HTMLBody = Replace(MyItem.HTMLBody, "Dear Person,", "Dear " & name)
'...
Set safeItem = CreateObject("Redemption.SafeMailItem")
Set oItem = MyItem
safeItem.Item = oItem
'this next line displays the email, and as of this line, it looks correct
'safeItem.Display
'but as of this line, the issue occurs
safeItem.HTMLBody = "<p>This is an extra message that shows up before the .msg file</p>" & safeItem.HTMLBody
safeItem.Recipients.ResolveAll
safeItem.Send
Now when the email is sent, the .msg contents aren't present at all -- the only thing that shows up is the "extra message" that I prepended to the HTMLBody.
What do I need to change or update? Is this something I need to change in the code, or in my Outlook settings, etc?
Extra: body insertion:
Function insertStringBodyTag(htmlBody As String, stringToInsert As String)
Dim s As String
Dim i As Integer
s = htmlBody
i = InStr(1, s, "<body")
i = InStr(i, s, ">")
s = Left(s, i) & stringToInsert & Right(s, Len(s) - i)
insertStringBodyTag = s
End Function
'Called with safeItem.htmlBody = insertStringBodyTag(safeItem.htmlBody, prefix_string)
You cannot concatenate 2 HTML strings and expect a valid HTML string back - the two must be merged - find the position of the "<body"substring in the original HTML body, then find the positon of the following ">" (this way you take care of the body element with attributes), then insert your HTML string following that ">".

How to email multiple doclinks of those who are my direct reports in the view?

I have a question. For example there is one view and 10 documents are in that view. Out of all those documents, 8 of them I should be the recipient of the email (based on the field value which is my email address).
Now, what I want to happen is that I will be receiving only one email for all those 8 documents, and in that email I there will be 8 doclinks.
Is that possible?
'Cause currently I am getting 8 emails and for each email, there is one doclink. Thanks in advance for those who can help me.
Dim s As NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim i As Integer
Dim view As NotesView
Set s = New NotesSession
Set db = s.CurrentDatabase
Set view = db.GetView("View")
Set doc = New NotesDocument(db)
Dim addresses As NotesName
i=0
Set doc = view.GetFirstDocument
While Not(doc Is Nothing)
Set addresses = New NotesName(doc.Manager(0))
If addresses.abbreviated = "" Then
i = i + 1
Else
doc.SendTo = addresses.abbreviated
doc.Form = "Memo"
Set rtitem = New NotesRichTextItem(doc, "Body")
Call rtitem.AppendText("Balance")
Call rtitem.appenddoclink(doc, "Link")
doc.Send (True)
i = i + 1
End If
Set doc = view.GetNextDocument(doc)
Wend
As Thorsten said, it can be done. There are a couple of ways to handle this, depending on how flexible and future proof you want it, and how "clean" of a solution you want.
Let's say you have 10 documents, 8 with your email and 2 with a different user's email. I assume you want to send one mail to you with 8 doc links and one to the other person with 2 doc links.
The way I would do it is to create a class. That class would contain a list of NotesDocuments (and a method to add documents to the list):
Class DocData
Public docs List As NotesDocument
Public Sub New()
End Sub
Public Sub Add(doc as NotesDocument)
Set docs(doc.UniversalID) = doc
End Sub
End Class
In your main code, you have a list of DocData objects, one per mail recipient:
Dim docs List As DocData
You now loop through the view or the document collection you have. You check the email address for each document and if there isn't a list item for that address, you create it and add the document to it. If it already exists, just add the document:
email = doc.GetItemValue("EmailAddress")(0)
If !IsElement(docs(email)) Then
Set docs(email) = New DocData()
End If
Call docs(email).Add(doc)
When all documents have been processed, you should have a list with one item per mail recipient, and you can loop through the list, build one email per item and populate it with doc links for all the documents in the list in the object.
For performance reasons, if you plan to have this working on larger views with more documents, I woudl suggest that you put the email address in one of the columns, and then use view entries to loop though the documents, and ColumnValues() to read the email address.
I wrote about it here: http://blog.texasswede.com/re-using-lotusscript-lists-to-increase-performance/
Your code can be slightly modified to only send one mail:
Dim s As NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim i As Integer
Dim view As NotesView
Set s = New NotesSession
Set db = s.CurrentDatabase
Set view = db.GetView("View")
Set doc = New NotesDocument(db)
Dim addresses As NotesName
i=0
'- prepare mail
doc.Form = "Memo"
Set rtitem = New NotesRichTextItem(doc, "Body")
Call rtitem.AppendText("Balance")
Set doc = view.GetFirstDocument
While Not(doc Is Nothing)
Set addresses = New NotesName(doc.Manager(0))
If addresses.abbreviated = "" Then
i = i + 1
Else
'- Set recipient
If not doc.HasItem( "SendTo" ) then
doc.SendTo = addresses.abbreviated
End If
'- Append descriptive text, link and new line
Call rtitem.appendtext(doc.Subject(0) & " " )
Call rtitem.appenddoclink(doc, "Link")
Call rtitem.addnewline(1)
i = i + 1
End If
Set doc = view.GetNextDocument(doc)
Wend
'- send mail
Call doc.Send (True)
with that code the mail is first prepared, then a doclink is added for every document, and in the end the mail is sent.

Message after sending mail asp.net

string Emails = "";
foreach (GridViewRow gr in gvregview.Rows)
{
CheckBox chk = (CheckBox)gr.FindControl("Checked");
Label ID = (Label)gr.FindControl("lblEmail");
Label lbl = (Label)gr.FindControl("lblPass");
Label Lblmrno = (Label)gr.FindControl("Lblmrno");
if (chk.Checked == true)
{
SendMail(ID.Text, lbl.Text);
//lblmsg.Text = "Mail Sent to "+Lblmrno.Text;
Response.BufferOutput = true;
puposalda.MailSentResponse = Lblmrno.Text;
//Response.Write("Mail to sent to" + Lblmrno.Text);
System.Threading.Thread.Sleep(500);
}
}
Hi Everybody, i want to send mail to all selected users in gridview and display Message 'Mail sent to the user UserName' for each user. Mail is sent successfully but only last user name is displaying. How to do that. Response.write is working but it is displaying message on the top. But i want to display message at specific location.
Thanks
Thanks
lblmsg.Text += "Mail Sent to "+Lblmrno.Text+", ";
in that case you ADD the text, not replace it.
I want to replace text not append Text. When mail to the first user has been sent successfully. Then message should display on the page. then same for other users.

Send HTML email asp

I want to add some html in an email. I've tried the following.
vFromName = "someone"
vFromAddress = "someemail"
vTo = "recipient"
vSubject="someSubject"
vBodyofemail = "<html><table><tr><td><b>SomeText</b></td></tr></table></html>"
Call SendMail()
sub SendMail()
'change to address of your own SMTP server
strHost = "mail.internal.rouses.com"
Set Mail = Server.CreateObject("Persits.MailSender")
'enter valid SMTP host
Mail.Host = strHost
'From eMail address
Mail.FromName = vFromName
'From address
Mail.From = vFromAddress
'To eMail address
Mail.AddAddress vTo
'message subject
Mail.Subject = vSubject
'message body
Mail.Body = vBodyOfEmail
Mail.Send
end sub
How can i do this? I've tried Mail.HtmlBody but that doesn't work either. The email is sent but all i see are the tags where the html is.
According to this page you need to set the IsHTML flag to true.
strHTML = "Hello world"
Mail.IsHTML = True
Mail.Body = "<HTML><BODY><CENTER>" & strHTML & "</CENTER></BODY></HTML>"
Try adding this line above the send call.
Mail.IsHTML = true
Without it, the Mail object defaults to standard text and whatever is typed into the Body property will be rendered in the email as text.
Not an answer to your question, but shouldn't all messages include plain text as well? Without plain text, you'll surely get a higher spam score.
(And people like myself prefer to switch to plain text if your HTML/CSS is not rendered well. See Guide to CSS support in email clients (2008), and the list at the Email Standards Project.)