get 'From' or sender address from apple's Mail - email

I'm new to scripting and am trying to write a simple script for mail. I need sender address from that or we can say From address. But I'm not getting anything from it. My script is as below.
tell application "Mail"
try
set theSelectedMessage to selection
set msgCount to count of theSelectedMessage
if (msgCount = 1) then
set theMsg to item 1 of theSelectedMessage
#also tried this
#set theSender to extract name from sender of theMsg
set theSender to (sender of theMsg)
display dialog "name:" & theSender
end if
end try
end tell
Dialog is coming but no detail of sender.

Basically extract name from is the right way
tell application "Mail"
set selectedMessages to selection
if selectedMessages = {} then return
repeat with aMessage in selectedMessages
set senderName to extract name from sender of aMessage
set senderAddress to extract address from sender of aMessage
display dialog " name: " & senderName & return & "address: " & senderAddress
end repeat
end tell

Ohhhh
I forgot to enable my mail account cause of that I was facing problem.
Mail > Preferences > Accounts > Account Information > Enable this account

Related

How to send automatic mails from QTP (not summary !!)

So I know how to send automatic summary mails from QTP.
But this is not the kind of informations I need, in fact I want the LongComments of my tests.
The thing is the content of "test result" mails are exactly what I need, so this is perfect but how to send it automatically at the end of my tests ?
I mean the point of using QTP is automation and I'm not able to automate one of the functionnality of the soft, I'm quite perplexed here...
The following function will work if you have an outlook agent installed and logged in on your test machine. You might have to write case statements based on your test results.
You can also access the mail server directly that way you don't have to install/login an outlook agent.
Function sendemail
Set objOutlook = CreateObject("Outlook.Application")
Set sndmail= objOutlook.CreateItem(0)
'Set properties
sndmail.To = "abc#gmail.com"
sndmail.CC = "abc#gmail.com; def#yahoo.com"
sndmail.Subject = "Sending mail"
sndmail.Body= "Test Contents"
sndmail.Attachments.Add("C:\Test.txt") 'Path of the file
'Send the mail
sndmail.Send
'Clear object
Set sndmail= Nothing
Set objOutlook = Nothing
End Function
Function fnSendEmailFromOutlook
'Create an object of type Outlook
Set objOutlook = CreateObject("Outlook.Application")
Set myMail = objOutlook.CreateItem(0)
'Set the email properties
myMail.To = "some_mail_id#gmail.com"
myMail.CC = "some_mail_id_2#gmail.com; some_other_mail#yahoo.com" 'Sending mails to multiple ids
myMail.BCC = "" 'If BCC is not required, then this line can be omitted
myMail.Subject = "Sending mail from MS Outlook using QTP"
myMail.Body= "Test Mail Contents"
myMail.Attachments.Add("D:\Attachment.txt") 'Path of the file to be attached
'Send the mail
myMail.Send
Wait(3)
'Clear object reference
Set myMail = Nothing
Set objOutlook = Nothing
End Function

Forwarding multiple emails as attachment into a new email from excel vba

Can anyone help me with excel vba code to send multiple/specific emails that are present in my inbox as an attachment in a new mail to someone I want.
so basically what I am asking for is if I go to my outlook express inbox and select lets say three mails and then click on the forward button on the ribbon it will create a new mail item with the mails that were selected as an attachment. I want this to be automated from excel vba.
Please any help will be highly appreciated.
Regards,
Premanshu
I have found answer for my question after some more search from one online forum/community and have been able to modify that according to my need. Posting the code below for anyone's reference and also the link for the original post that I used and modified for my purpose.
Sub ForwardSelectedItems()
On Error Resume Next
Dim myolApp As Outlook.Application
Dim objItem As Outlook.MailItem
Set objOL = CreateObject("Outlook.Application")
If objOL.ActiveExplorer.Selection.count = 0 Then
MsgBox ("No item selected")
Exit Sub
End If
For Each objItem In objOL.ActiveExplorer.Selection
Set objMsg = objItem.Forward()
With objMsg
.Display
For Each itm In objOL.ActiveExplorer.Selection
.Attachments.Add itm, olEmbeddeditem
Next itm
.Subject = "example"
.To = "example#example.com"
.Body = “”
.Send
End With
Exit For
Next
Set objItem = Nothing
Set objMsg = Nothing
End Sub
the link for the popst I refered to is:-
Forwarding Outlook Item as attachment and adding it to a category in the same VBA macro
Thank you all.
Regards,
Premanshu

How to make an excel table that automatically sends email to someone on his birthday?

I need to write a formula that recognizes when someone's birthday is and trigger www.zapier.com.]
I have a birthday-recognition formula that creates a "send email" hyperlink, but I need it to be automatically sent (and delayed to 10am) non-interactively. I also did something in VBA but I only managed to write code that sends that message to 1 person.
Here's the working birthday-recognition formula. Client names are in column C8:C100, emails are in D8:D100, DOBs are in E8:E100 and the "send mail" hyperlinks are in F:100.
=IF(TEXT(E13;"d.m")=TEXT(TODAY();"d.m");HYPERLINK("mailto:"&D13&"? subject="&$D$2&"&body="&SUBSTITUTE(SUBSTITUTE($E$3;"$";C13);"#";$D$4);"pošalji čestitku");"")
"pošalji čestitku" = send mail (croatian language)
VBA code:
Private Sub CommandButton1_Click()
POŠALJIROĐENDANSKEČESTITKE
End Sub
Public Function POŠALJIROĐENDANSKEČESTITKE()
Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")
Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = Cells.Range("D8:D1000")
olMail.subject = "Sretan rođendan"
olMail.Body = "Poštovani," & vbCrLf & vbCrLf & "Želimo Vam sretan rođendan"
& vbCrLf & vbCrLf & "Sve najbolje," & vbCrLf & vbCrLf & "svinaweb"
olMail.Send
End Function
This code just sends the message to one email when I click on the command button, but as I said I want it to be sent to every person that has a birthday today and to delay the sending of the emails to 10am instead of midnight.
I am using Excel 2013.
The Recipients property of the MailItem class returns a Recipients collection that represents all the recipients for the Outlook item.
The Recipients class provides the the Add method to create a new Recipient object and add it to the Recipients object. The Type property returns or sets the type of recipient. It can be one of the following OlMailRecipientType constants: olBCC, olCC, olOriginator, or olTo.
So, you can send the single email to all people. You just need to add them to the Recipients collection. Or, if you need to have individual message bodies, you can create separate email messages.
The DeferredDeliveryTime property of the MailItem class allows to set a Date indicating the date and time the mail message is to be delivered.

Why is a memo created and sent from a LotusScript agent converting rich text to plain and removing document links?

We have a Document Library set up to accept user administration requests from our managed school districts. I recently made some updates to the form used to enter requests and some minor changes to the agent used to notify our administrators of the new request. Since these changes, the notification emails, which were once being received in rich text with an embedded document link, are now coming in as plain text. I have reverted both the form and the agent to previous versions and email message remains plain text. The agent's code follows.
Option Public
Use "Variables"
Dim db As NotesDatabase
Sub Initialize
On Error Goto gotError
Set s = New NotesSession
Dim doc As NotesDocument
Dim kbaseDb As NotesDatabase
Dim kdoc As NotesDocument
Set db = s.CurrentDatabase
Set doc = s.DocumentContext
Dim fromName As NotesName
Dim commName As String
Set fromName = s.CreateName(doc.from(0))
commName = fromName.Common
Dim memo As New NotesDocument(db)
Dim body As NotesRichTextItem
memo.Form = "Memo"
memo.SendTo = techEmail
memo.Subject = doc.categories(0) + " admin request from " + districtName
If doc.priorityflag(0) = "Priority" Then
memo.Subject = doc.Categories(0) + " PRIORITY admin request from " + districtName
memo.DeliveryPriority = "H"
End If
Set body = memo.Createrichtextitem("Body")
Call body.AppendText("Please process this " + doc.action(0) + " request from " + commName + ".")
Call body.AddNewLine(2)
Call body.AppendText("Comment: " + doc.comment(0))
Call body.AddNewLine(1)
Call body.AddNewLine(1)
Call body.AddNewLine(1)
Call body.AppendText("Link to request ")
Call body.AppendDocLink( doc, "Link to request ")
Call memo.send(False)
Call doc.ReplaceItemValue("OwnerNotified", doc.Owner)
Call doc.Save(True, False)
Exit Sub
gotError:
Print "<b><FONT color=red>System Error (" + Str(Err) + "): " + Error
Exit Sub
End Sub
It seems like it's something to do with the signer of the agent- unless somehow your reversion to the original agent hasn't worked.
Here's a set of things I woudl check :
Identify the person who the agent is running as. It's usually the signer, or web user if it's a web agent and "Run as web user" is ticked on the agent properties.
Check their entry in the NAB. If they have their mail system NOT set to Notes, then the server's email sending settings must come into action when sending on their behalf - check the server document in the NAB, under MTAs .. Message Content field. I believe this tells the server how to send such emails.
If this is the issue, then fixes would be :
* Sign the agent with another Id who uses Notes Mail
* If you can't sign with another Id, set the email system of the signer to Notes Mail
Fingers crossed..
The fix was to change the "Message Content" setting for outbound MIME conversion. This is set to "Convert from Notes to plain text" by default and needed to be changed to "Convert from Notes to HTML".
Details are on this page in the InfoCenter:
http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=%2Fcom.ibm.help.domino.admin.doc%2FDOC%2FH_SPECIFYING_MIME_CONVERSION_OPTIONS_OVER.html

Outlook 2007: Create a message rule that detects autoforwarded messages and handles them

I'm looking for kind of the opposite of creating a rule to auto-forward
emails. I want to create a rule that acts on RECEIVED auto-forwarded emails,
but not any that were manually forwarded or replied to by the same person.
E.g. Jim forwards me all emails with "blah" in the subject, and I want to
move those auto forwards to my "Jim's auto-forwards" folder, but if he
forwards me a message manually that says "blah" but he adds his own comments,
I want it to stay in my inbox.
Outlook seems to know that it is auto forwarded, as it shows up
as such when you view the email. Just above the "From" section but
just below the ribbon, it says something like:
"This message was AutoForwarded."
However I haven't found any option to create a rule filtering these.
Our exchange server (Outlook maybe?) adds the following headers when auto-forwarding:
Auto-Submitted: auto-generated
X-MS-Exchange-Generated-Message-Source: Mailbox Rules Agent
(Visible by opening an email and viewing the message "Properties" to see the headers) These appear to be what Outlook is using to detect that a message was AutoForwarded (or at least coincide)
And Outlook/Exchange 2013 has the filter option "with specified words in the message header"
I have used a rule that looks similar to the following to successfully move only "blah" subject messages autoforwarded from "Jim" to a specific folder:
Apply this rule after the message arrives
from 'jim#example.com'
and with 'blah' or 'blurg' in the subject
and with 'auto-generated' or 'Auto-Submitted' in the message heade
move it to the 'Jims auto-forwards' folder
And this has appeared to prevent any that he's manually forwarded from being processed by the same rule.
Our Exchange Server adds the following header for Auto Forwarded and Auto Replies
X-MS-Exchange-Inbox-Rules-Loop: abc#company.com
where abc#company.com is the email of the person auto forwarding the email.
I use MS Outlook 2010 in which i have setup a rule ->
From: abc#company.com
and with 'X-MS-Exchange-Inbox-Rules-Loop: abc.xyz#company.com'
or 'X-MS-Exchange-Inbox-Rules-Loop: abc.XYZ#company.com' in the message header
move it to the 'xyz' folder
i have checked abc.xyz#company.com as well as abc.XYZ#company.com in message header as in some auto Fwd/Re email header the Lastname of the sender was uppercase.
Note: as mentioned before this rule applies to all Auto Forwarded and Auto Replies (e.g Out of office/ vacation auto replies) from that person. Manual Fwd/RE emails are not filtered
I do not think rules can do this.
Try some VBA. untested
Edit 2013 02 26
Put the code in ThisOutlookSession http://www.slipstick.com/outlook-developer/how-to-use-outlooks-vba-editor/
Here are some references so you can debug if necessary.
NewMailEx: http://msdn.microsoft.com/en-us/library/office/bb147646(v=office.12).aspx
AutoForwarded Property: http://msdn.microsoft.com/en-us/library/office/ff867162.aspx
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim varEntryIDs
Dim objItem
Dim i As Integer
Dim myOlApp As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myDestFolder As Outlook.MAPIFolder
varEntryIDs = Split(EntryIDCollection, ",")
For i = 0 To UBound(varEntryIDs)
Set objItem = Application.Session.GetItemFromID(varEntryIDs(i))
'Debug.Print "NewMailEx " & objItem.Subject
If objItem.SenderName = "Jim Smith" Then
If objItem.AutoForwarded then
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
' Assumes destination folder is directly under the Inbox
Set myDestFolder = myInbox.Folders("Jim AutoForwarded")
objItem.Move myDestFolder
End If
End If
Next
Set objItem = Nothing
Set myDestFolder = Nothing
Set myInbox = Nothing
Set myNameSpace = Nothing
End Sub