الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

how to send email with attchment

مغلق
بدأه BMW316i في 2 فبراير 2003 · 19 رد · 1,335 مشاهدة · في منتدى تصميم صفحات الويب
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

how i can send email with attchment

my email object

Set SendEmail = Server.CreateObject("SMTPsvg.Mailer")

SendEmail.FromName   = Request.form("yourname") 'Specify sender's address

SendEmail.FromAddress= Request.form("youremail")

SendEmail.RemoteHost = "mail.nbcbn.com"

SendEmail.AddRecipient Request.form("Yourfriendemail")

SendEmail.Subject    = Request.form("yourtitle")

SendEmail.ContentType ="text/html"

SendEmail.BodyText   = strMsg

so how i can make attachment

#3

أخي حسب خصائص كل كائن بريدي يمكنك ارسال البريد .. مثلا في كائن ال CDONTS العام و الشائع و المجاني يمكنك أرفاق رسالة بإضافة تعليمة واحدة فقط للكود المعتاد لارسال البريد و هي كالتالي :

 path="c:webhostourFolderyrFolderfile.Zip"

 mailObj.FileAttach path

طبعا راجع نتائج الكائن الذي اخترته انت من الدعم الفني لموقعك لأنه من المفترض أن يكون هو من أعطاك إياه :)

You can fly while you can touch the sky

#4

هذا هو الجواب :

   Set SendEmail = Server.CreateObject("SMTPsvg.Mailer")

    SendEmail.FromName   = Request.form("yourname") 'Specify   sender's address

    SendEmail.FromAddress= Request.form("youremail")

    SendEmail.RemoteHost = "mail.nbcbn.com"

    SendEmail.AddRecipient Request.form("Yourfriendemail")

    SendEmail.Subject    = Request.form("yourtitle")

    SendEmail.ContentType ="text/html"

    SendEmail.BodyText   = strMsg

    SendEmail.AddAttachment  filePathOnServer

ما تنسى ان المتغير filePathOnServer يجب أن يحوي على مسار كامل للمف المراد ارفاقه مع الرسالة على السيرفر و يمكنك استخدام طريقتين لذلك و هي إما ال Uploader أو حسابات ال FTP الخاصة بموقعك ..

و هذا أحد المراجع

http://www.aspfaq.de/index.asp?FID=108&ELE=9400 (ألماني الموقع لكن الكود مفهوم :) )

You can fly while you can touch the sky

#6

في هذه الحال ستحتاج لأبلودر يقوم برفع الملف و سيكون من المؤكد أن اسم الملف عندك و بالتالي يبقى باقي المتغيرات و انت حر بها مثل لمن يرسل و هكذا..

You can fly while you can touch the sky

#8

بسيطة تعمل الأبلودر يرفع الملفات في صفحة مستقله و عند رفع الملف يقوم بارسال اسم الملف عن طريق hidden input وقد طرحنا هذا الموضوع سابقا باسم " الحفاظ على الحالة " .. و بعدين عادي كمل باقي الحقول و ارسلها و من بينها الحق المخفي الذي يحمل اسم الملف الذي تم رفعه ..

اعتقد ان الموضوع بسيط ..

You can fly while you can touch the sky

#12

هل تقصد حذف الملف من السيرفر بعد ارسال البريد ؟؟

ان كان جوابك نعم فهناك طريقتان ..

الأولى : عمل حذف دوري .. أي أن المدير يقوم بإفراغ محتويات المجلد مرة واحدة ..

الطريقة الثانية هي حذف الملف نفسه..

طبعا سيكون اسم الملف موجود و كل ما عليك هو اضافة سكريبت في دالة تستدعى بعد الارفاق و الارسال و تقوم بحذف الملف مستندة على الطريقة :

set FSO=Server.CreateObject("Scripting.FileSystemObject")

set File=FSO.GetFile(filePathOnServer)

File.Delete

You can fly while you can touch the sky

#14

:) مش ضروري عمل دوال لكنها أسهل و أرتب كمبرمج و قد شرحتها ألف مرة .. و هذا مثال :

   Function GetUserName(id)

      if id<>0 then

        set rs=cn.execute("SELECT * from users where userId="&id)

         if not rs.Eof then           

            GetUserName=rs("user")

         end if

      end if

    End Function



  

 recRs=cn.execute("Select * From Members")

   while not recRs.Eof 

     response.write GetUserName(recRs("userId"))

   recRs.MoveNext

   wend

You can fly while you can touch the sky

#15

أيضا مثال لدالة مساعدة يمكنك أن تفعلها ..

  Function delFile(path)

    set FSO=Server.CreateObject("Scripting.FileSystemObject")

    set File=FSO.GetFile(path)

    File.Delete

  End Function



 ' here the code of sending email 

  '

  '

  '

  ' 

  mailObj.Send

  mailObj.close

  Set mailObj=nothing



  pathOnServer="c:webhost4lifeurAccountFolder"

  fileName=request("fileName") ' it is the value of the hidden input which hold the uploaded file

  filePath=pathOnServer & fileName

  call delFile(filePath)

You can fly while you can touch the sky

#16

هو داه الكود اللى انا كتبته بس فى اخطاء مش عارف ايه هيه

<%response.buffer=true

Dim userscnn , usersrs

Set userscnn = Server.CreateObject("ADODB.Connection")



userscnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("search.mdb") & ";"

Set usersrs = Server.CreateObject("ADODB.Recordset")

usersrs.Open "SELECT * FROM users where Title = '" & Session("node") & "' OR Title = 'Secretariat' OR MyGroup = 1",  userscnn , 1, 2



Dim userscnn1 , usersrs1

Set userscnn1 = Server.CreateObject("ADODB.Connection")



userscnn1.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("search.mdb") & ";"

Set usersrs1 = Server.CreateObject("ADODB.Recordset")

usersrs1.Open "SELECT * FROM users Where  User_Name = '" &  Session("temp") & "'",  userscnn , 1, 2

usersrs1.MoveFirst

%>

<HTML>

<HEAD>

<META http-equiv=Content-Type content="text/html; charset=unicode">     

    <%

    Func = Request("Func")

   	 

	if isempty(Func) then

      Func = 1

	end if



    Select case Func

  case 1

    %>

	<script language="JavaScript" type="text/JavaScript">

<!--



function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}

//-->

</script>

<SCRIPT LANGUAGE="JavaScript">



<!-- Changes:

// -->



<!-- Begin

function emailCheck (emailStr) {





var checkTLD=1;





var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;





var emailPat=/^(.+)@(.+)$/;





var specialChars="()><@,;:".[]";





var validChars="[^s" + specialChars + "]";





var quotedUser="("[^"]*")";





var ipDomainPat=/^[(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})]$/;





var atom=validChars + '+';





var word="(" + atom + "|" + quotedUser + ")";



// The following pattern describes the structure of the user



var userPat=new RegExp("^" + word + "(." + word + ")*$");





var domainPat=new RegExp("^" + atom + "(." + atom +")*$");





var matchArray=emailStr.match(emailPat);



if (matchArray==null) {





alert("Email address seems incorrect (check @ and .'s)");

return false;

}

var user=matchArray[1];

var domain=matchArray[2];



// Start by checking that only basic ASCII characters are in the strings (0-127).



for (i=0; i<user.length; i++) {

if (user.charCodeAt(i)>127) {

alert("Ths username contains invalid characters.");

return false;

   }

}

for (i=0; i<domain.length; i++) {

if (domain.charCodeAt(i)>127) {

alert("Ths domain name contains invalid characters.");

return false;

   }

}



// See if "user" is valid 



if (user.match(userPat)==null) {



// user is not valid



alert("The username doesn't seem to be valid.");

return false;

}



/* if the e-mail address is at an IP address (as opposed to a symbolic

host name) make sure the IP address is valid. */



var IPArray=domain.match(ipDomainPat);

if (IPArray!=null) {



// this is an IP address



for (var i=1;i<=4;i++) {

if (IPArray>255) {

alert("Destination IP address is invalid!");

return false;

   }

}

return true;

}



// Domain is symbolic name.  Check if it's valid.



var atomPat=new RegExp("^" + atom + "$");

var domArr=domain.split(".");

var len=domArr.length;

for (i=0;i<len;i++) {

if (domArr.search(atomPat)==-1) {

alert("The domain name does not seem to be valid.");

return false;

   }

}





if (checkTLD && domArr[domArr.length-1].length!=2 && 

domArr[domArr.length-1].search(knownDomsPat)==-1) {

alert("The address must end in a well-known domain or two letter " + "country.");

return false;

}



// Make sure there's a host name preceding the domain.



if (len<2) {

alert("This address is missing a hostname!");

return false;

}



// If we've gotten this far, everything's valid!

return true;

}



//  End -->

</script>

<script language="JavaScript">

<!--

function MM_findObj(n, d) { //v3.0

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document); return x;

}



//-->

</script>

<script language="JavaScript">

<!--

<!--

function paymentmove() {



var ind;

ind = main.Yourfriendname.options.selectedIndex;

main.Yourfriendemail.value = main.Yourfriendname.options[ind].value;





//alert(ind);

}



// -->



function MM_validateForm() { //v4.0

  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args);

    if (val) { nm=val.name; if ((val=val.value)!="") {

      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');

        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.n';

      } else if (test!='R') { num = parseFloat(val);

        if (isNaN(val)) errors+='- '+nm+' must contain a number.n';

        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');

          min=test.substring(8,p); max=test.substring(p+1);

          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.n';

    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.n'; }

  } if (errors) alert('The following error(s) occurred:n'+errors);

  document.MM_returnValue = (errors == '');

}

//-->

</script>

</HEAD>

<BODY>

<P><FONT face=Arial color=blue size=4><STRONG>Select a File to send as attachment.</STRONG></FONT> 

</P>

<FORM ENCTYPE="multipart/form-data" ACTION="sendmail.asp?func=2" METHOD=post id=form1 name="main" onSubmit="return emailCheck(this.Yourfriendemail.value)" >

  <TABLE width="475" BORDER=0 align="center" CELLPADDING=0 CELLSPACING=0 bordercolor="#336699" bgcolor="#336699">

    <TR> 

      <TD ALIGN=RIGHT width="171"><font size="3" color="#FFFFFF" face="Times New Roman, Times, serif">From 

          Name: </font>
</TD>

      <TD colspan="2">  <FONT COLOR="#000000">	<%= Session("temp")%> 

          <INPUT TYPE="hidden" NAME="yourname"  SIZE=40 MAXLENGTH=70 value="<%= Session("temp")%>">

          </FONT> 
</TD>

    </TR>

    <TR> 

      <TD ALIGN=RIGHT width="171"> <font size="3" color="#FFFFFF" face="Times New Roman, Times, serif">From 

          E-mail : </font>
</TD>

      <TD colspan="2"> <FONT COLOR="#000000">	<%= usersrs1("Email") %> 

          <INPUT TYPE="hidden" NAME="youremail"  SIZE=40 MAXLENGTH=70 value="<%= usersrs1("Email") %>">

          </FONT> 
</TD>

    </TR>

    <TR> 

      <TD ALIGN=RIGHT width="171"> <font size="3" face="Times New Roman, Times, serif"></font>
</TD>

      <TD width="180"> </TD>

      <TD width="123" valign="middle"> </TD>

    </TR>

    <TR> 

      <TD ALIGN=RIGHT width="171"> <font size="3" face="Times New Roman, Times, serif"></font>
</TD>

      <TD width="180"> <font color="#FF0000" size="2">NBCBN 

          Members </font>
</TD>

      <TD width="123" valign="middle"> <font color="#990000" size="2"></font>
</TD>

    </TR>

    <TR> 

      <TD ALIGN=RIGHT width="171"> <font size="3" color="#FFFFFF" face="Times New Roman, Times, serif">To 

          Name: </font>
</TD>

      <TD>  

          <select name="Yourfriendname" onBlur="paymentmove();">

            <option>Nodes Members</option>

            <% Do While Not usersrs.EOF%>

            <option value="<%= usersrs("Email") %>"><%= usersrs("user_name") %></option>

            <%  usersrs.MoveNext  

             Loop  %>

            <option value="Please Enter Mail Here">Non Members</option>

          </select>

        
</TD>

      <TD></DIV></TD>

    </TR>

    <TR> 

      <TD ALIGN=RIGHT width="171"> <div align="right"><font size="3" color="#FFFFFF" face="Times New Roman, Times, serif">To 

          E-mail : </font>
</TD>

      <TD colspan="2">  

          <INPUT TYPE="text" NAME="Yourfriendemail" VALUE="" SIZE=40 MAXLENGTH=70>

        
</TD>

    </TR>

    <TR> 

      <TD ALIGN=RIGHT> <font color="#FFFFFF" size="3" face="Times New Roman, Times, serif">Subject 

          : </font>
</TD>

      <TD colspan="2">  

          <input type="text" name="mailsubject" value="" size=40 maxlength=70>

        
</TD>

    </TR>

    <TR> 

      <TD width="171" height="20" ALIGN=RIGHT><FONT COLOR="#FFFFFF" size="3" face="Times New Roman, Times, serif"><strong>Attachments</strong>:</FONT></TD>

      <TD colspan="2"><INPUT NAME=File12 SIZE=30 TYPE=file></TD>

    </TR>

    <TR> 

      <TD width="171" height="166" ALIGN=RIGHT valign="top"><font size="3" color="#FFFFFF" face="Times New Roman, Times, serif">Message: 

        </font></TD>

      <TD colspan="2" valign="baseline">  

          <textarea name='message' cols="35" rows="10" wrap=SOFT><%=request.form("message")%></textarea>

        
</TD>

    </TR>

    <TR> 

      <TD ALIGN=RIGHT width="171"> </TD>

      <TD colspan="2"> 


          <INPUT TYPE="image" NAME="Send Comments" VALUE="Send " onClick="MM_validateForm('Yourfriendemail','','RisEmail');return document.MM_returnValue" SRC="IMAGES/Send_NUntitled-1.gif" WIDTH="83" HEIGHT="23">

        


      <td width="1"> 

  </TABLE>

  <%

    

  case 2

 	 ForWriting = 2

     	 adLongVarChar = 201

     	 lngNumberUploaded = 0

   	 

    'Get binary data from form  

     	 noBytes = Request.TotalBytes 

        binData = Request.BinaryRead (noBytes)

    

    'convert the binary data to a string

     	 Set RST = CreateObject("ADODB.Recordset")

        LenBinary = LenB(binData)

   	 

       	 if LenBinary > 0 then

          RST.Fields.Append "myBinary", adLongVarChar, LenBinary

         	 RST.Open

            RST.AddNew

           	 RST("myBinary").AppendChunk BinData

            RST.Update

          strDataWhole = RST("myBinary")

       	 End If

    

    'Creates a raw data file for with all data sent. Uncomment for debuging.	

   	 'Set fso = CreateObject("Scripting.FileSystemObject")

   	 'Set f = fso.OpenTextFile(server.mappath(".") & "raw.txt", ForWriting, True)

   	 'f.Write strDataWhole

   	 'set f = nothing

   	 'set fso = nothing

    

    'get the boundry indicator

    strBoundry = Request.ServerVariables ("HTTP_CONTENT_TYPE")

    lngBoundryPos = instr(1,strBoundry,"boundary=") + 8 

    strBoundry = "--" & right(strBoundry,len(strBoundry)-lngBoundryPos)

    

    'Get first file boundry positions.

    lngCurrentBegin = instr(1,strDataWhole,strBoundry)

    lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1



do while lngCurrentEnd > 0

 	 'Get the data between current boundry and remove it from the whole.

 	 strData = mid(strDataWhole,lngCurrentBegin, lngCurrentEnd - lngCurrentBegin)

    strDataWhole = replace(strDataWhole,strData,"")

     	 

 	 'Get the full path of the current file.

      lngBeginFileName = instr(1,strdata,"filename=") + 10

     	 lngEndFileName = instr(lngBeginFileName,strData,chr(34)) 

    

 	 'Make sure they selected at least one file.	

      if lngBeginFileName = lngEndFileName and lngNumberUploaded = 0 then

   	 

     	 Response.Write "<h2> The following error occured.</h2>"

     	 Response.Write "You must select at least one file to upload"

     	 Response.Write "

Hit the back button, make the needed corrections and resubmit your information."

     	 Response.Write "

<input type='button' onclick='history.go(-1)' value='<< Back' id='button'1 name='button'1>"

     	 Response.End 

   	 

      end if

    

 	 'There could be one or more empty file boxes.	

      strFilename = mid(strData,lngBeginFileName,lngEndFileName - lngBeginFileName)

    

 	 'Creates a raw data file with data between current boundrys. Uncomment for debuging.	

      'Set fso = CreateObject("Scripting.FileSystemObject")

      'Set f = fso.OpenTextFile(server.mappath(".") & "raw_" & lngNumberUploaded & ".txt", ForWriting, True)

      'f.Write strData

      'set f = nothing

      'set fso = nothing

      

 	 'Loose the path information and keep just the file name.	

      tmpLng = instr(1,strFilename,"")

     	 

     	 do while tmpLng > 0

        PrevPos = tmpLng

        tmpLng = instr(PrevPos + 1,strFilename,"")

     	 loop

      

        FileName = right(strFilename,len(strFileName) - PrevPos)

   	 

 	 'Get the begining position of the file data sent.

 	 'if the file type is registered with the browser then there will be a Content-Type

     	 lngCT = instr(1,strData,"Content-Type:")

   	 

        if lngCT > 0 then

       	 lngBeginPos = instr(lngCT,strData,chr(13) & chr(10)) + 4

          

          else

            lngBeginPos = lngEndFileName

        end if

    

 	 'Get the ending position of the file data sent.

      lngEndPos = len(strData) 

      

 	 'Calculate the file size.	

      lngDataLenth = lngEndPos - lngBeginPos

    'Get the file data	

     	 strFileData = mid(strData,lngBeginPos,lngDataLenth)

    

    ' Create the file, change the path to the path U use for temp storage of the file

    ' make sure you have the IUSR_YOURCOMPUTER granted WRITE access to the uploads dir

     	 Set fso = CreateObject("Scripting.FileSystemObject")

        Set f = fso.OpenTextFile(server.mappath("/Attachment") & "/" & FileName, ForWriting, True)

       	 f.Write strFileData

    

      ' Get full Path, you need it for deleting the file later 	 

       	 Dim ThisFile

        ThisFile = server.mappath("/Attachment") & "/" & filename

    

          lngNumberUploaded = lngNumberUploaded + 1

      

      ' destroy f, free memory

        set f = nothing

      

  'Get then next boundry postitions if any

   	 lngCurrentBegin = instr(1,strDataWhole,strBoundry)

     lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1

loop

   	 

    ' CDO mail object

    Set objCDOMail = Server.CreateObject("CDONTS.NewMail")

    

    ' CDO mail setttings

  with objCDOMail

 	 .Body = "TestMailtje met attachment!"

 	 .Subject = "testing 123"

 	 .From = "test@nbcbn.com"

 	 .To = "administrator@nbcbn.com"

 	 '.Cc = strCC    

 	 .MailFormat = 0 	 

 	 .AttachFile ThisFile

 	 .Send

  end with



	' destroy object, free memory

	set objCDOMail = nothing

    

    ' Now the file in the uploads dir can be deleted

    fso.DeleteFile ThisFile

    

    ' Destroy FileSystemObject, Free memory

    set fso = nothing

          

      Response.Write "Uw mail is verstuurd!</h2>"

      Response.Write "

<input type='button' onclick='document.location=" & chr(34) & "sendmail.asp" & chr(34) & "' value='<< Back' id='button'1 name='button'1>"        

   	 

end select	

    

  

    %></FORM>

    </BODY>

    </HTML>

Microsoft VBScript runtime error '800a0034'

Bad file name or number

/sendmail.asp, line 394

#18

معلشى يا جماعه انا عارف الكود كبير بس علشان لما تجربه تعرفو الخطاء فيين علشان ميكونش الكود مش كامل ورقم السطر الذى يوجد به الخطاء يدل على ان مكان الرفع فيه مشكلة

ويوجد سؤال اخر هيمكن ارسال اللايمال لاكثر من شخص فى نفس الوقت انا بجربها دلوقتى و هكتبلكم الكود علشان تساعدونى

#20
اقتباس
ايه يا جماعه محدش عبرنى  

هل من مساعده

و الله يسعدنا انا نساعدك لكن أخي مثل هذه الأكواد من الصعب التدقيق فيها

انت المبرمج و انت تعرف ماذا تفعل .. نحن نرشدك و نساعدك تقنيا فقط .. انت أدرى بكودك ..

حظا موفقا..

You can fly while you can touch the sky

هذا الموضوع مغلق.

مواضيع مشابهة