我正在尝试使用python中的MIMEmultipart库发送电子邮件, 但是,除了附件,我在接收端得到了一堆随机文本。我引用了MIME documentation,但我的错误仍然存在!
其他answers也没有帮助。
这是脚本:
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
gmailUser = 'asikday@gmail.com'
gmailPassword = 'khfskh'
recipient = 'arunt14@gmail.com'
message='your message here '
msg = MIMEMultipart()
msg['From'] = gmailUser
msg['To'] = recipient
msg['Subject'] = "Subject of the email"
msg.attach(MIMEText(message))
msg.attach(MIMEText(file("temp.png").read()))
mailServer = smtplib.SMTP('smtp.gmail.com', 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmailUser, gmailPassword)
mailServer.sendmail(gmailUser, recipient, msg.as_string())
mailServer.close()
以下是我通过电子邮件收到的一些文本:
IHDR 'iCCPkCGColorSpaceAdobeRGB1998 c``RH,( N.(*a`` [$) JR+J@ s~AeQfzF EePc pHYs IDATx nE%E d7." T)GE >|XN 4bT" UF%rXZ IW$r /\f~ {pE" c7=pm" 8.@" ,@"' 8.@" ,@"' 8.@" 5j$U jRRRd ,{ey" ?^RSS- &s:t nz_G 3Bu9O ,@"' 7['t :#GgI >o%K }PXj0 $I 55 D_JJJ }{K(} -'9@ :thh K 5jdI, $r<; $IMM &NL+ 8)0q xK < Z5#; !?}" !?=$ $r<7 !CBq |KH$r, hQh o SOEs evB0 ]tfM )X=?], <0;' ;/$r, $q<< _/%K .~:' >|X> t@gZ VN*C SO=%'O v5A=I 3r|5 .E5g @xrn qc)[ 2ml<N 3X4y eKK[ 4ibi H\&{ x]@?\ $A g 7o^i eA@gQ /_>x |ZfI xty5 eHn@ 2-\oz pa`/7 :$z^ _^#& >'sB 9ai2 {4S" 9,h_ 5iR) */$rL '8L: X9F _~)G CYZW= *UJn D\JJJ` wk11 .d9f O?-e gGC'O cR)Q < 9r M`Jt >9&& 6lX`) IDATe 5k&G qCB@n s&.W N;v.g HII1*d dE@gF B" i`=z pcRD ={vy Ph2G +WFsi [oMt *4iY ,8+A >1m- j(/a! a!(7 ^ZV-H 6mZR# O7?P"D 6IMM EI|F ~O8= |&0z ")))bJ"G7! ={v` CCMV &q4QKA [uC)S <&@" ;wnR} %555y lY`F 6a4y P<1q/ M(_} 6cmL -%{v $u ` 4L(, dA O MYVM 5k$Y \#@" F4YEA W %% Wy[` EO.G ~})V vmL1 >?Tv rj={ SEg&9 zN4O ;vNE ng,0v tov* 99CI =\ti < 0z }c@G 8QtM < 9r d*@"'S". nv<} \,0p p\@g \^-55Uf v\dZ" D_0g LXj1 vVI] ^@WC 'gi] Z0X' $FlmJ $K g xF { 9sF&O q1m6 ;vLj 8=+g ?$={ ;wnOu g=6Jt |=&B (v$m zM)_ 928[ (U"' ne{C8 .+qO )J{Mi$ 6A7E 7o^IB 4hPI 9M$S +U & Nmn3e 7N4:a z#&@ $r*l 8&v. YMC2 ]To71 @ H NiIo !~ K!@ ] 0`@E$s w\Xb ?'M- Gj5N :u*Rk 4&sb =z$o1g ]IC 2eJQ +a&M !&uVYe B\}Vi% l5%r *qexL~+ ZJ\] O%&qj *'V+~ W^Y% g@FB np"#@ W_}uIB V5UL 0`@Xk ;C|3HIC nQ95F `tB"@ HP@"' R_3z nKf0 5jTn ;vl2 O?M& W^9L @ 1 Z*;/ U+oCV [nY& {\Y5~ 0=&@ C}zz *V &Nz IDAT W_}5 O ~`r W^y% V\iu 2u/L UVY% sOvFA UU?N (5Tj +&{j H &| (X@" G@"' (X@" G@"' (X@" G@"' (X@" G@"' (X@" G@"' 5T @ $rJN 9MsS 4M@" $rJN 4N@" fl7~ b<M)' 7(:t ]b2' ;N/j Ka1a _<[Q SN9%\} 0&z. vNK\ W\qEv DN)T ]w]vn vWq{ ve</j I'eI }6k*n EiO# _/ZLo 3fLQ lL#7 4)\y ;KJ5t} %Z:u }Bl/ >Xh{ 6-[U $r*e 6qEP +gbYn OM{S DN*3! W_}5 Wd+u J+e+ HI@"' C*b\ @ E sgVXa 3gNYbI 6lXV $<9B#@ UW%= $r*e _~yx \pAx SO5X luEC cB<oG!@ %[1q 7dob 3fL8 *'~- 2eJx $rjaxH HI@"' @ % 0<$@ PK@" vV.il? IDAT @N;> A7wm r2@f H"@ ' d @ ' r2@f H"@ ' d @ ' r2@f H"@ ' d @ ' r2@f H"@ ' d @ ' r2@f H"@ ' d @ ' 'O6_ i&/y h#3d 2hYXr .a/O[ %}nU0G n=w~* (I_FN9 W^1/ ^o'= sHr?PK zC;H3 T~x` gu^ZG vMM+T x5|Q [/i] ({\a+F R=qF ^G=s j;La wLI_ fSs; t-Du.Z} t5SR cV[m5 ]0I= i*JJ UW$qH [7[^ \=mj%] 9ol[\ FCn)i ~{h^ 3n>Q -vyR ,s7l &Gu- ^U+w= ^y+_ V\qE mToF zA3\{>L UW5j, jzx_+ `V[m5 yw,m nv,z am4,X 1GM+ J=(W )R=_y,m ^XyL W+ix <G)w z3i~ <G)| l;?J )Z=_] `S G z0N9j hr=m ^UO\= [MR[ 'i(/ omVq F_X] A_;^a Yohgi zkX5= _~9V ^xas fP+H <,ih5 k@A$} <G)W (jROa _G=z ;l(= 2Urs Y7%-S '0Cy :tHL t6(K "K5V "@ ' @N}# rrag 'O6_ {n92 ju_s {{/PP ]v1O? SO5z cRk7. _|af }v[_ AA{H K/5G J=3* ^=$V/ ELz0 X]Y|_ RJjI IDAT k>IR ,c?{ Fce'I ^9aIC RpOeQ v}F'! 5?=D Q%=, S[!j P+\= (I=a47 s|U_ JCNe 9X|&7 |WcgU &q>C XS0B j4wHVI zMjh:M6 z/rr @N;8 P-P $cCW -f7s WjO_ q6mh] :?ng g Gv zp-+ %4'DPR ^hI{ u~*w 25*Xs >iGn Zh!;t] +=\O3ix a$u? TV}F ;t%^ pi&= S//= ZtkN !+5q b=,TJ TsOhx V 8, S{Ji\ r\+\ Vk?>^S 4W^y TsKhhOM VY_} j=j> _z/} o_{-hBv MSY? 95px =-j9 }]hn. !o4v |kHC GKZNW 9A*,C hrc= PjdX C%=h M2[' 33;) RR/B vx%= ^P=z ,ey~ FZ#kh5} *k#Is8 <b&I !I>Y T~8V* buwl [*?</ Y9hS* ;}f- EMY] BuLB ~S~Xh HmK@=,4 ']sj @NT) @ @@ K/mz '@ ' %@ '.I %@ '.I %@ '.I %@ '.I %@ '.I %@ '.I %@ '.I %@ '.I %@ '.I %@ '.I kg={ R=r2%YL n58R qV=~ \=yT 8>8R 2$W> (Hmz $o2E 5+1'N IDATA 7nla P`Fs,n RS1{7U /@ '~SrD 5jTi .]j7 /_nK VEPe !HPF ,LR@I +WVa-* q0U| .@ ' YG7$ g6H9/^ Pe6n {BTO cH}} sb]> IX[_ J.H .QT> Oj}4GP z#e;?*W w+y} KU}? ;2%= zmDI Nr> ^Jy_~ kGC&e {v_V UW4%#P Q`FO =AU|? !p2M> r=iG PIC) \sM^%j o\/[ O=n4D@j G o_7n krs5 K.1= $.[= $'u!ON: aR\u L_Vu nr^| c/(C &]/z rSXu -Zd{ s=gv wJ-s 7oM O_w8 !9{< Z7W_ e$o .]jC +hYd d)tj :g^*Ws z+x4~ -[V%=C C-S ovF> <j^Q M=0F [laC 7S>! [EK4 xH-O :i]>y ^m#G &@ ' &@ ' !@ ' Awa; (@ '" R`&Lp 96R`a njW\q .@ ' ;,R^ &@ ' Q#cE @ ' @ Y ,z7(x *9N] )@ '$ P0'L wUU#c N-]! UW]e+V (@ ' 5*j r%m3q U:w} >['?~@ j(@ ,X`k Y/[5 ^=q4 bW+Q &=WR </O= 5jdg 5?Xj @Nu> +h*D _?uS~. OS@8SR &Myh qt-i <7lMQ+@a IDATQC ^9JK Q GC 9RO1% q( Z @N~n `Q@!lPA lqWM yk^! ^sY( P>Iy Z)Is CrFzJXO K=V| !P&M oW\q Fr5~ z~) &'}_P`C UN\I S}5^ I>I 49O}VcQ =B=H4 -S`( ,LRo K.#L~ vjH? )S S :]?> `S N FObk( i(<% *Y@A P?>( N8!p GO7
谢谢!