Outgoing function email () { var box = ""; var ids = ""; if ($ (": Checkbox[name= ' Deltrain ']:checked"). Size () = = 0) { alert ("You did not select data to be sent out!"); return; } if (!confirm (' Do you really want to send out the selected app? ')) { return false; } var c = 0; $ ("Input[name= ' Deltrain ']:checked"). each (function () { C + +; Box = $ (this); IDS = $ (this). attr (' value '); }); if (c = = "1") { Dialog.open ({id: "Window_waifa", Title: "Outgoing", width:920, height:500, Url:top.rootdir + '/inf_trai n/email/' + IDs + "?" + Query, Openerid:iframeid}); } else { alert (' Outgoing can only select one piece of data!!! ') return false; }
/// <summary> ///Outgoing Mail/// </summary> /// <returns></returns> PublicJsonresult emailsend () {jsonresult result=NewJsonresult (); Getpubparameter (); varID = request["ID"]; varTomail = request["Tomail"]; varCcMail = request["CcMail"];
varNoticetitlemeal = request["Noticetitlemeal"]; varNoticecount =""; Inf_train model =NewInf_train (); Model=Bll.getmodel (ID); if(Model! =NULL) { Noticecount=model. Noticecount; } #regionGet Attachment AddressDataTable DT= Annexbll.getmodel ("ID = '"+ ID +"' and invalid!= ' 1 '"); string[] n =NULL; if(dt. Rows.Count >0) {n=New string[dt. Rows.Count]; for(inti =0; i < n.length; i++) { if(dt. rows[i]["Annexpath"]. ToString ()! =NULL|| Dt. rows[i]["Annexpath"]. ToString ()! ="") {N[i]= Server.MapPath (dt. rows[i]["Annexpath"]. ToString ()); } } } #endregion //declare a message that can be sent with SmtpClientMailMessage mail =NewMailMessage (); //set the subject of the messageMail. Subject ="you have a new message"; StringBuilder content=NewStringBuilder (); Content. Append ("Topics:"). Append (noticetitlemeal). Append ("<br/>"); content. Append ("content:"). Append (Noticecount). Append ("<br/>"); //declaring outgoing mail objectsMailhelper Mailhelper =NewMailhelper (); //calling the outgoing mail method BOOLs = Mailhelper.sendemail (Tomail.replace (",",","), Ccmail.replace (",",","),"","", Noticetitlemeal, content. ToString (), n); if(s) {result. Data=New{success =true }; Mailhelper.sendemaillog (train_id,"", Noticetitlemeal, Tomail.replace (",",","), Ccmail.replace (",",","), Emailfrom, content. ToString (), N,""); } Else{result. Data=New{success =false }; } return result; }
<add key= "smtpserver" value= "XXXXXX. Xxxxxx.com "/>
<add key=" UserName "value=" [email protected] "/>
<add key= "Pwd" value= "..."/>
<add key= "AuthorName" value= "..."/>
static readonly string smtpserver = System.configuration.c onfigurationmanager.appsettings["SmtpServer"];
static readonly string emailfrom = system.configuration.configurationmanager.appsettings["UserName"];
static readonly string password = system.configuration.configurationmanager.appsettings["PWD"];
static readonly string authorname = system.configuration.configurationmanager.appsettings["AuthorName"]; /// <summary> ///Send mail/// </summary> /// <param name= "Mailtolist" >mailbox to send (multiple comma-separated not null)</param> /// <param name= "CCList" >cc Mailbox (multiple comma-separated allow null)</param> /// <param name= "Repalyto" >reply to a mailbox (multiple comma-separated allow null)</param> /// <param name= "Bcclist" >bcc mailbox (multiple comma-separated allow null)</param> /// <param name= "Mailsubject" >Mailbox Subject</param> /// <param name= "Mailcontent" >Mailbox Content</param> /// <param name= "Attachmenturl" >attachment URL (preceded by @ or escaped, control. postedfile.filename) (array)</param> /// <returns>returns the result of sending a mailbox</returns> Public Static BOOLSendEmail (stringMailtolist,stringCCList,stringRepalyto,stringBcclist,stringMailsubject,stringMailcontent,string[] attachmenturl) { //Mail Service SettingsSmtpClient SmtpClient =NewSmtpClient (); Smtpclient.deliverymethod= Smtpdeliverymethod.network;//specify how e-mail is sentSmtpclient.host = SmtpServer;//Specify the SMTP serverSmtpclient.credentials =NewSystem.Net.NetworkCredential (emailfrom, password);//user name and passwordMailMessage MailMessage =NewMailMessage (Emailfrom, mailtolist);//Add a group of recipients//Send mail Settings if(!string. IsNullOrEmpty (CCList)) {MAILMESSAGE.CC.ADD (cclist);//Add a group of CC } if(!string. IsNullOrEmpty (Repalyto)) {MAILMESSAGE.REPLYTOLIST.ADD (Repalyto);//Add a group of replies } if(!string. IsNullOrEmpty (bcclist)) {MAILMESSAGE.BCC.ADD (bcclist);//add a set of Bcc } if(attachmenturl!=NULL) { if(Attachmenturl.length >=1) { if(! (Attachmenturl.length = =1&& attachmenturl[0] =="")) { for(inti =1; I <= attachmenturl.length; i++) { //determine if a file exists if(File.exists (Attachmenturl[i-1]. ToString ())) {Attachment myfiles=NewAttachment (Attachmenturl[i-1]);//Uploading AttachmentsMailMessage.Attachments.Add (myfiles); } } } } } mailmessage.subject= Mailsubject;//"test subject";//ThemeMailmessage.body = mailcontent;//Message Contentmailmessage.bodyencoding = Encoding.UTF8;//Body Codemailmessage.isbodyhtml =true;//set to HTML formatmailmessage.priority = Mailpriority.low;//Priority Level stringEndinformation =string. Empty; Try{smtpclient.send (mailmessage);//Send mailEndinformation ="sent successfully"; return true; } Catch(Smtpexception ex) {endinformation="Send failed:"+Ex. ToString (); return false; } }
Send Message method