View Full Version : Using .net for accessing Outlook

Alex Morris
12 December 2008, 06:01 PM
Hi guys,

Following a post on here about accessing explorer using dot net I started playing around with outlook with the aim of automating email notification:

fn createEmail =
attachmentFilePath = getOpenFileName caption:"Select a file to attach to the email"
createMsgSwtch = "/c ipm.note "
recipientSwtch = "/m "
attachmentSwtch = ("/a \""+@(attachmentFilePath)+"\"")
process = dotNetObject "System.Diagnostics.Process"
process.EnableRaisingEvents = false
process.StartInfo.FileName = "outlook"
process.StartInfo.Arguments = (createMsgSwtch + recipientSwtch + attachmentSwtch)

However the attachment bit is causing problems. Any ideas on how to get this to work and maybe fill in the email and send it? I'm not very familiar with .net so assume I know nothing.....


Alex Morris
12 December 2008, 09:15 AM
oops.... posted this in the wrong forum can someone move it into the Maxscript one please?

Alex Morris
12 December 2008, 09:11 AM
thanks for moving the thread - so does anyone have any ideas?

12 December 2008, 09:42 AM
Hi Alex, I can't help with outlook as I run Vista with the default windows mail client. However, I will have a poke around on the net if i get a spare minute and see if I can convert some VB into a max friendly function.

Alex Morris
12 December 2008, 09:48 AM
thanks Pete,

I tried a few things to get the same functionality like NetworkManager.Send, but I thought if I could feed this a body of text and a subject, all I'd have to do would be check the content and hit send - the templates and signatures are already there on our system.

Hmmm, hadn't considered Vista - we're on XP64. Does windows mail connect through Exchange, or is it more like outlook express?

12 December 2008, 10:12 AM
Hi Alex,

i think Windows Mail in Vista is probably the replacement of Outlook Express. Are you looking to use outlook because you use it in the Office? Outlook could be problematic as the bits i've read start talking about using COM assemblies, in which case you'd need an Interop assembly to use with .Net methods.

There might be other avenues to send mail through .net - I've looked at using the System.Net.Mail assembly as this has an example on MSDN but it's framework v3.5 and im having an issue with -

dotnetobject "System.Net.Mail.MailAddress" MailAddressString

MailAddress takes a string as a constructor in VS, but min Max it doesnt want to know.

I'll try to look into it further but I might have to sign off now and do some work!

Alex Morris
12 December 2008, 10:25 AM
I think if I can get the syntax right on the attachment part of the existing code then that would be ok for now.
I had a similar issue doing the same thing through hiddenDosCommand:

recipientStr = " /m "+" ("
attachmentFilePath = " /a "+"\"C:\\\\Documents and Settings\\AlexM\\My Documents\\My Pictures\\12259_large.jpg\""
cmdString = ("\"S:\\\\Program Files (x86)\\Microsoft Office\\OFFICE11\\OUTLOOK.EXE\" /c ipm.note"+(recipientStr)+(attachmentFilePath))
print cmdString
HiddenDOSCommand cmdString startpath:"S:\\"

In the .net code maybe the string is the problem with the attachment argument as well? I thought initially that maybe it was the number of arguments (switches) that was the problem, but it works from the command console using run.

We're set up across the office to use Outlook, but I suppose if there is a method of bypassing this straight to the outgoing mail server that might work too.

12 December 2008, 11:26 AM
dotnetobject "System.Net.Mail.MailAddress" MailAddressString
Odd.. works here - are you sure you're feeding it a valid address?

email = dotNetObject "System.Net.Mail.MailMessage"
email.from = dotNetObject "System.Net.Mail.MailAddress" "" (dotNetObject "System.Net.Mail.MailAddress" "")
email.subject = "hello world"
email.body = "This is a mail test!"
email.attachments.add (dotNetObject "System.Net.Mail.Attachment" "c:\\temp\\mavence.jpg")
smtp = dotNetObject "System.Net.Mail.SMTPClient" = ""
smtp.send email

Alex Morris
12 December 2008, 11:29 AM
Ahaa! thanks Richard.

I'll give this a try. The only problem I see is getting it into my sent items so I have a record of what was sent. But I guess I can just copy myself in on the email for that.

12 December 2008, 11:34 AM
nice one rich, must make note not to try to write any code before first cup of tea. :)

I wonder if there's any way of providing SMTP authentication with this class, as this method gets bumped by my mail server.

12 December 2008, 11:54 AM
I don't use Outlook myself on this machine, but if you want to go through outlook itself then I think you have to install the .NET programming..somethingorother, which installs an assembly (which you'd then load, etc. etc.)

Though it should be possible to go via the command-line as well.. but I'm not sure you can invoke an actual sending of the message.. most mail clients only allow you to start composing one, but leave 'hitting send' to the user

12 December 2008, 12:04 PM
I wonder if there's any way of providing SMTP authentication with this class, as this method gets bumped by my mail server.
If you're lucky, you can use...

smtp.Credentials = dotNetObject "System.Net.NetworkCredential" "username" "password"

If you're unlucky, you may have to dig into the credentials system, although it might just be that your mail server requires an SSL connection when authenticating.. in which case 'smtp.enableSSL = true' would be your friend

CGTalk Moderation
12 December 2008, 12:04 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.