Current location - Education and Training Encyclopedia - Resume - The problem of calling outlook to send mail with python
The problem of calling outlook to send mail with python
I will print out your error message. "xd2 \ xd1\ xd6 \ xd5 \ xd6 \ xb9 \ xb2 \ xd9 \ xd7 \ xf7" means "operation terminated"

Now it seems that com made a mistake. I haven't adjusted my point of view. But I think it should work. Because there are few documents on the COM interface.

You can learn this interface from VBA documentation first. Find some examples of C++ calling outlook.

The following is an example I found on the Internet. for reference only

#! /usr/bin/env? Python

"""

Answer? Simple? Address? Books? Browser. ? Descending? Become? That? Depth? about

Yours Exchange? Server? Through? Outlook? And then what? Found it? That? contacts

List. ? then what Excerpts? Those? Contact!

Attention:? Generation? That? Type? Library? For what? Microsoft? Outlook? First of all.

Mail? information

-

Are you online? MSDN? That? Interface? Is it? On record? Down there? "Messaging? and

Collaboration ",?" Collaboration? Data? Object ",?" CDO? for

Windows? 2000",?" CDO? For what? Windows? 2000",?" Messaging ",

"concept" “CDO? Messaging? COM? Interface ",? "That? IMessage

COM? Interface ",?" IMessage? Attribute ".

Unfortunately,? Isn't it? All of them? Attribute? Is it? Always? Available.

Really? That? gen_py '? Directory? Inside? Site package? May? be

Answer? More? Is it accurate? Summary? Yes? Attribute? And then what? Interface.

Saved? project

-

typedef? enum? {

olTXT? =? 0,

olRTF? =? 1,

olTemplate? =? 2,

olMSG? =? 3,

Aldo? =? 4,

olHTML? =? 5,

Ovka? =? 6,

Orfkar? =? seven

}? OlSaveAsType

Dating? Articles? Is it? Saved? As? vCal? By who? By default.

Contact? Articles? Is it? Saved? As? vCard? By who? By default.

Mail? Articles? Is it? Saved? As? Words? By who? By default.

All of them? Other? Articles? Is it? Saved? As? Words? By who? By default.

"""

Import? win32com.client

Import? sys,? Operating System (operating system)

#? This? Is it? Need? Before? we? Is it okay? Even? Talk? About what? Different? enum? Values.

Outlook? =? win32 com . client . dispatch(" Outlook。 Application ")

Class? View:

"A? Opinion? Go? Namespace.

def? __init__(self, code):

"initialization? That? Opinion? With what? Answer? Personality? Encoding.

Self-coding =? encode

Class? Console view (view):

"A? Console style? View. "

Show namespace attribute mapping? =? {

win32 com . client . constants . ol folder? :

("+",? "Name"),

win32 com . client . constants . ol contact? :

(" >,?" E-mail 1 address "),

win32 com . client . constants . olmail? :

(" >,? "theme"),

No? :

("?" ,? "Name")

}

def? __init__(self, code,? page_width=80,? page_limit=20):

"""

Initialize? That? Opinion? With what? Answer? Personality? Coding? And then what? That? optional

Page width'? And then what? Page _ Limit'.

"""

View. __init__(self, code)

self.page_width? =? Page width

self.page_limit? =? Page limit

def? Update_status (self, counter,? max_value):

"update? Answer? Status? Indicators? With what? That? Given? Counter? Value? And then what? Maximum value.

last_counter? =? Max (counter? -? 1,? 0)

Finally _ width? =? int((last_counter? *? self.page_width)? /? Maximum value)

Width? =? Int ((counter? *? self.page_width)? /? Maximum value)

sys.stdout.write(" . "? *? (width? -? Last _ Width))

What if? Counter? ==? Maximum value:

sys.stdout.write("\n ")

def? Error (self):

sys.stdout.write("!" )

def? Show_namespace (itself, project):

"Performance? That? Namespace,? Given? Answer? List? Yes? Item', "

What if? Len (item)? & gt? self.page_limit:

Print? "!" ,? "Show? That? The first "," self.page_limit,? "items? Only. "

For what? Value? Are you online? items[:self.page_limit]:

Try:

Decoration? Property? =? self . show _ namespace _ property _ mapping[value。 Category]

Except? Critical error:

Decoration? Property? =? Self.show _ namespace _ property _ mapping [none]

Print? Decoration? Self.get_property (value,? Attribute). Coding (self-coding)

def? get_property(self,? Object? Property,? Default value = "":

Try:

#? Attention:? Black!

What if? Property? ==? "Senton":

Return? Getattr(object, property). Format ()

Return? Getattr(object, attribute)

Except? Attribute error:

Return? System default value

Class? Extractor:

"A? Class? Used? For what? That? Extract? Yes? Articles/objects? From where? Folders

Extract _ Type _ Mapping? =? {

win32 com . client . constants . ol appointment? :

(win32 com . client . constants . olvcal,? "venture capital"),

win32 com . client . constants . ol contact? :

(win32 com . client . constants . olv card,? “vcf”),

win32 com . client . constants . olmail? :

(win32 com . client . constants . ol txt,? “txt”),

No? :

(win32 com . client . constants . ol txt,? " txt ")

}

def? __init__(self, view = none):

"initialization? That? Extractor? With what? That? Optional? View "."

self.view? =? visual angle

def? Extract (self,? Articles,? File name):

"Excerpts? That? Given? Project? Where to? Answer? Documents? With what? That? Given? File name "."

Total _ Quantity? =? Len (project)

For what? Me? Are you online? Range (0,? Total):

Value? =? Item [i]

Try:

Save as type,? Suffix? =? self . extract _ type _ mapping[value。 Category]

Except? Critical error:

Save as type,? Suffix? =? Self. extract _ type _ mapping[ none]

Try:

Value. SaveAs(os.path.join (file name, str(i)? +? "."? +? Suffix),

Save as type)

Except? Attribute error:

What if? Self-view:

self.view.error()

Except? win32 com . client . pywintypes . com _ error:

What if? Self-view:

self.view.error()

What if? Self-view:

self.view.update_status(i? +? 1,? Total)

Class? Resource manager:

"A? Class? Maintenance? That? Status? Yes? Explore. "

def? __init__(self, view = none):

Global? view

Self current? =? self.ns? =? Looking ahead. GetNamespace("MAPI ")

self.view? =? visual angle

Self. _get_namespace()

def? Up (oneself):

"ascension? Become? That? Parents? Folder? Return? Is it? It? Used to be. It is possible. "

What if? Self current? ! =? Self ns:

Self current? =? Self. Current. Parents

Self. _get_namespace()

Return? 1

Return? 0

def? Down (self, name):

"""

Descending? Become? That? Folder? With what? That? Given? Name? Return? Is it? it

Is it okay? Is it? It's done.

"""

What if? self.choices.has_key(name):

Self current? =? self.choices[name]

Self. _get_namespace()

Return? 1

Return? 0

def? get_items(self):

"Return? Answer? List? Yes? Articles? Are you online? That? Currently? Folders

Return? Self project

def? Get a choice (self):

"Return? Answer? A dictionary? Mapping? Name? Where to? Object. "

Return? Self-selection

def? _get_namespace(self):

"""

Ann? Inside? Method? Which one? Refresh? That? Currently? Namespace.

"""

Self-choice Self-belongings? =? get_namespace(self.current,? Self-view)

def? Get_namespace (namespace, view = none):

"""

Get? That? Content? Yes? That? Given? Namespace',? Return? Answer? A dictionary? about

Choice? (Is it appropriate? For what? Folder)? And then what? Answer? List? Yes? Articles? (Is it appropriate? for

Message).

"""

d? =? {}

l? =? []

#? First of all? Try it? Looking for? For what? Folders ? then what See? For what? Project. ? And then what? So what? Open.

For what? Attribute? Are you online? (("folder",? "Name")? ("articles",? None)):

#? See? For what? Object? Yes? That? Currently? Type:? Folder,? Articles,? Wait a minute.

object_name? =? Attribute [0]

Try:

Child object? =? Getattr (namespace, object name)

Except? Attribute error:

#? Ignore? That? Rest? Yes? That? Cycle? Body? And then what? begin

#? That? Next? Iteration.

continue

#? Index? That? Got it back? Articles? By who? Storage? They? By who? Name? Are you online? Answer? A dictionary.

#? Can't? Slice? Articles,? And then what? They? Always? Seems? Where to? Start? Where is it? Index? 1.

Total _ Quantity? =? Shot (sub-object)

For what? Me? Are you online? Range (1,? Total _ Quantity? +? 1):

Try:

field_name? =? Attribute [1]

#? Shop? Are you online? That? A dictionary? Use? That? Designated? Property,? if

#? Specify.

L.append (child object [i])

What if? field_name? Is it? Isn't it? None:

D[getattr (child object [i],? field_name)]? =? Child object [i]

Except? Attribute error:

get through

#? Rough-made? Status? Indicator.

What if? View:

View.update_status (I,? Total)

Return? d,? l

def? main():

#? Get? That? Coding? What if? Specify.

What if? len(sys.argv)? & gt? 2:

Coding? =? sys.argv[2]

Otherwise:

Coding? =? "UTF 8"

Opinion? =? Console View (Coding)

The seeker? =? Browser (view)

What time? 1:

#? Hint? That? Users.

Print? "-"? *? 60

view . show _ namespace(explorer . get _ items())

Print? "-"? *? 60

Print? "[beauty] p? Have? [E]xtract? [Q]uit? [H]elp? then what & ltReturn & gt! "

Print? "-"? *? 60

s? =? Original input (). Stripping (). upper()[0]

#? Found it? That? Right? Action.

What if? s? ==? “U”:

#? Get up.

explorer.up()

Elif? s? ==? “D”:

#? Hint? For what? That? Folder? Where to? Enter.

Print? "Come down? Become: "

Name? =? Original input ()

What if? Isn't it? Explorer.down (name):

Print? "No? Like this? Object. "

Elif? s? ==? “E”:

#? Hint? For what? That? Documents? Where to? Excerpts? To.

Print? "Excerpts? To: "

File name? =? Original input ()

Print? "Extracting ..."

Extractor? =? Extractor (view)

extractor . extract(explorer . get _ items(),? File name)

Elif? s? ==? "q":

Print? "Exiting ..."

Raise? System exit

Elif? s? ==? “H”:

Print? "type? That? d? Keys? then what & ltReturn & gt? Where to? Enter? Answer? Folders

Print? "give it? That? Exactly? Folder? Name? What time? Hint? And then what? News? & ltReturn & gt."

Print? "type? That? u? Keys? then what & ltReturn & gt? Where to? Moving? Up? One? Level. "

Print? "type? That? q? Keys? then what & ltReturn & gt? Where to? Quit. "

Print? "type? That? h? Keys? then what & ltReturn & gt? Where to? Reading? This? Here we go again. "

Print? "type? That? e? Keys? then what & ltReturn & gt? Where to? Excerpts? Item. "

Print? "give it? Answer? File name? What time? Hint? And then what? News? & ltReturn & gt."

print

Print? "all right? Luck! "

Otherwise:

Print? "No? Like this? Command. "

What if? __name__? ==? " __main__ "

Master ()

#? vim:? tabstop=4? expandtab? shiftwidth=4