public static void SendMessage(string name, string from, string img) { string tFrom = "*****@*****.**"; string tTo = "*****@*****.**"; string tSubject = "AA生活记账 - " + "欢迎" + ItemHelper.GetUserFrom(from) + "用户" + name; string dEncoding = "utf-8"; string tBody = GetBody(img); string tSmtpServer = "smtp.qq.com"; string tPort = "25"; string tLogin = "******"; string tPassword = ""; Dimac.JMail.Message message = new Dimac.JMail.Message(); message.From = tFrom; message.To.Add(tTo); message.Subject = tSubject; message.Charset = System.Text.Encoding.GetEncoding(dEncoding); message.BodyHtml = tBody; try { Dimac.JMail.Smtp.Send(message, tSmtpServer, short.Parse(tPort), GetDomain(message.From.Email), Dimac.JMail.SmtpAuthentication.Login, tLogin, tPassword); } catch { } }
public static void SendMessage(string name, string from, string img) { string tFrom = "*****@*****.**"; string tTo = "*****@*****.**"; string tSubject = "AA生活记账 - " + "欢迎" + name; string dEncoding = "utf-8"; string tBody = GetBody(img); string tSmtpServer = "smtp.qq.com"; string tPort = "25"; string tLogin = "******"; string tPassword = "******"; Dimac.JMail.Message message = new Dimac.JMail.Message(); message.From = tFrom; message.To.Add(tTo); message.Subject = tSubject; message.Charset = System.Text.Encoding.GetEncoding(dEncoding); message.BodyHtml = tBody; try { Dimac.JMail.Smtp.Send(message, tSmtpServer, short.Parse(tPort), GetDomain(message.From.Email), Dimac.JMail.SmtpAuthentication.Login, tLogin, tPassword); } catch { } }
static void Main(string[] args) { Console.WriteLine("1:gmail,2:163,3:hbu"); try { Dimac.JMail.Message jM; Dimac.JMail.Smtp smtp; switch (Console.ReadLine()) { case "1": Tools.SendMail.SendMailGmail("*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "test", Body()); break; case "2": Tools.SendMail.SendMail163("*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "163" + DateTime.Now, Body()); break; case "3": Tools.SendMail.SendMailhbu("*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "hbu" + DateTime.Now, Body()); break; case "4": Tools.obMail.SenddMail("*****@*****.**", "*****@*****.**", "hbu" + DateTime.Now, Body()); break; case "5": jM = new Dimac.JMail.Message(); jM.From.Email = "*****@*****.**"; jM.To.Add(new Dimac.JMail.Address("*****@*****.**")); jM.Subject = "163Jmail" + DateTime.Now; jM.BodyHtml = Body(); jM.Charset = System.Text.UTF8Encoding.UTF8; smtp = new Dimac.JMail.Smtp(); smtp.HostName = "smtp.163.com"; smtp.Authentication = Dimac.JMail.SmtpAuthentication.Login; smtp.Domain = "smtp.163.com"; smtp.UserName = "******"; smtp.Password = "******"; smtp.Send(jM); break; } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.InnerException); Console.WriteLine(ex.HelpLink); Console.WriteLine(ex.Source); Console.WriteLine(ex.TargetSite); Console.WriteLine(ex.StackTrace); } Console.WriteLine("success"); Console.ReadLine(); }
//3 type de smtp pour envoyer l'email par serveur //Jmail smtp public void sentEmail(string adressFrom, string psw, string stradresseRecu, string stradresseCC, string strSujet, string strbodymailhtml, string strbodymailtext, int indexPriorite) { Dimac.JMail.Message jmsg = new Dimac.JMail.Message(); string[] adresseRecu = getListAdress(stradresseRecu); string[] adressCC = getListAdress(stradresseCC); string mailSujet = strSujet; for (int i = 0; i < adresseRecu.Length; i++) { if (!string.IsNullOrEmpty(adresseRecu[i])) { jmsg.To.Add(adresseRecu[i]); } } for (int i = 0; i < adressCC.Length; i++) { if (!string.IsNullOrEmpty(adressCC[i])) { jmsg.Cc.Add(adressCC[i]); } } jmsg.Subject = mailSujet; jmsg.From = adressFrom; jmsg.Charset = System.Text.Encoding.UTF8; string mailbody = HttpUtility.UrlDecode(strbodymailhtml); jmsg.BodyHtml = mailbody; jmsg.BodyText = strbodymailtext; if (WebUserControl1.Emaildatastatic.getInstance().getDataTable().Rows.Count > 0) { foreach (DataRow dr in WebUserControl1.Emaildatastatic.getInstance().getDataTable().Rows) { jmsg.Attachments.Add(dr["filepath"].ToString()); } } switch (indexPriorite) { case 0: jmsg.Priority = Dimac.JMail.Priority.Medium; break; case 1: jmsg.Priority = Dimac.JMail.Priority.High; break; case 2: jmsg.Priority = Dimac.JMail.Priority.Low; break; } try { Dimac.JMail.Smtp.Send(jmsg, "smtp.qq.com", short.Parse("25"), "qq.com", Dimac.JMail.SmtpAuthentication.Login, adressFrom, psw); } catch (Exception ex) { string errmsg = "An exception occured: " + ex.Message; } }
static void Main(string[] args) { Console.WriteLine("1:gmail,2:163,3:hbu"); try { Dimac.JMail.Message jM; Dimac.JMail.Smtp smtp; switch (Console.ReadLine()) { case "1": Tools.SendMail.SendMailGmail("*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "test", Body()); break; case "2": Tools.SendMail.SendMail163("*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "163"+DateTime.Now, Body()); break; case "3": Tools.SendMail.SendMailhbu("*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "hbu"+DateTime.Now, Body()); break; case "4": Tools.obMail.SenddMail("*****@*****.**", "*****@*****.**", "hbu"+DateTime.Now, Body()); break; case "5": jM = new Dimac.JMail.Message(); jM.From.Email = "*****@*****.**"; jM.To.Add(new Dimac.JMail.Address("*****@*****.**")); jM.Subject = "163Jmail"+DateTime.Now; jM.BodyHtml = Body(); jM.Charset = System.Text.UTF8Encoding.UTF8; smtp = new Dimac.JMail.Smtp(); smtp.HostName = "smtp.163.com"; smtp.Authentication = Dimac.JMail.SmtpAuthentication.Login; smtp.Domain = "smtp.163.com"; smtp.UserName = "******"; smtp.Password = "******"; smtp.Send(jM); break; } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.InnerException); Console.WriteLine(ex.HelpLink); Console.WriteLine(ex.Source); Console.WriteLine(ex.TargetSite); Console.WriteLine(ex.StackTrace); } Console.WriteLine("success"); Console.ReadLine(); }