C#메일 발송
12881 단어 메일 보내기
1: public static bool Send(string host, string from, string fromPassword, string fromDisplayName, 2: List<ToMailAddress> toMailAddress, string subject, string body, out string desc, params string[] attachmentFileNames) 3: { 4: if (toMailAddress == null || 5: toMailAddress.Count == 0) 6: { 7: desc = " "; 8: return false; 9: } 10: try 11: { 12: 13: // SmtpClient , host (SMTP ),SMTP Internet 。 Host 。 SmtpClient smtpClient=new SmtpClient();smtpClient.Host=host; 14: SmtpClient smtpClient = new SmtpClient(host); 15: 16: // Send , , 100 000(100 ) 17: smtpClient.Timeout = 60000; 18: 19: // SMTP 。UseDefaultCredentials true,SmtpClient ( )。UseDefaultCredentials false, Credentials 20: // UseDefaultCredentials false Credentials , 。 21: smtpClient.UseDefaultCredentials = true; 22: 23: // 。 24: smtpClient.Credentials = new NetworkCredential(from, fromPassword); 25: 26: // 。 27: smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; 28: 29: // SMTP 。 30: //smtpClient.Port = 25; 31: 32: // SmtpClient (SSL) 33: //smtpClient.EnableSsl = true; 34: 35: //MailMessage SmtpClient SMTP 36: MailMessage message = new MailMessage(); 37: 38: // 39: message.SubjectEncoding = Encoding.UTF8; 40: 41: // 42: message.BodyEncoding = Encoding.UTF8; 43: //message.From = new MailAddress(from, fromDisplayName, Encoding.UTF8); //.net4 44: 45: // 46: message.From = new MailAddress(from); 47: //message.Sender = new MailAddress(from, fromDisplayName); 48: 49: // Html 。 Html , true; false。 false。 50: message.IsBodyHtml = true; 51: 52: // 53: message.Subject = subject; 54: 55: // 56: message.Body = body; 57: 58: // 59: message.Priority = MailPriority.Normal; 60: 61: // 62: SetToMailAddress(toMailAddress, message); 63: 64: // 65: // SetAttachments(attachmentFileNames, message); 66: 67: // 68: smtpClient.Send(message); 69: 70: // 71: //smtpClient.SendAsync(message, null); 72: 73: // , smtpClient 74: smtpClient.Dispose(); 75: desc = " "; 76: return true; 77: } 78: catch (Exception ex) 79: { 80: desc = ex.Message; 81: return false; 82: } 83: } 84: 85: private static void SetToMailAddress(List<ToMailAddress> toMailAddress, MailMessage message) 86: { 87: toMailAddress.ForEach(mailAddr => 88: message.To.Add(new MailAddress(mailAddr.Address, mailAddr.DisplayName, Encoding.Default))); 89: 90: } 91:
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
UiPath로 자동 메일 보내기 VBScript 및 배치 파일, 공휴일 캘린더 사용폐사에서는 일하는 방법 개혁을 위해, 건전하고 화제의 RPA를 도입했습니다. 본사에서는 WinActor를 메인으로 사용하고 있는 것 같다. 공장에서는 해외 전개도 생각하고 있으므로 UiPath 의 2개 기둥이 될 것...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.