לא קיבלתי כזו הודעה.
פורסם במקור בפורום CODE613 ב01/09/2016 14:27 (+03:00)
לא קיבלתי כזו הודעה.
פורסם במקור בפורום CODE613 ב01/09/2016 14:27 (+03:00)
צרפתי.
צריך Visual Studio 15 Preview 4 כדי לפתוח.
העלו פה קישור להתקנה.
פורסם במקור בפורום CODE613 ב31/08/2016 13:49 (+03:00)
ב app.config
פורסם במקור בפורום CODE613 ב31/08/2016 13:04 (+03:00)
Send.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Net;
using System.Net.Mail;
using System.Text;
public class MessageGmail
{
//חשוב להקפיד שהערכים יהיו כך
//key=שם הנמען,value=כתובת המייל שלו
public Dictionary<string, string> ToList { get; set; } = new Dictionary<string, string>();
public string Subject { get; set; }
public string Body { get; set; }
public bool IsBodyHtml { get; set; } = false;
public List<Attachment> ListFileAttachment { get; set; } = new List<Attachment>();
}
public static class SendMail
{
private static string senderName = ConfigurationManager.AppSettings["From"].ToString();
private static string senderEmailId = ConfigurationManager.AppSettings["SMTPUserName"].ToString();
private static string password = ConfigurationManager.AppSettings["SMTPPasssword"].ToString();
private static MailAddress fromAddress = new MailAddress(senderEmailId, senderName);
public static bool SendEMail(MessageGmail message)
{
var success = false;
var msg = createMessage(message);
msg = addFilesToMessage(message, msg);
var client = createClient();
try
{
client.Send(msg);
success = true;
}
catch (Exception ex)
{
//להוסיף דיוח על שגיאה אם רוצים
}
return success;
}
private static MailMessage createMessage(MessageGmail message)
{
MailMessage msg = new MailMessage()
{
From = fromAddress,
Subject = message.Subject,
Body = message.Body,
IsBodyHtml = message.IsBodyHtml,
SubjectEncoding = Encoding.UTF8,
BodyEncoding = Encoding.UTF8
};
//מצרף את כתובות המייל לשליחה
foreach (var address in message.ToList)
{
var ToAddress = new MailAddress(address.Value, address.Key);
msg.To.Add(ToAddress);
}
return msg;
}
private static SmtpClient createClient()
{
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = new NetworkCredential(fromAddress.Address, password);
return client;
}
private static MailMessage addFilesToMessage(MessageGmail originalMessage, MailMessage msg)
{
if (originalMessage.ListFileAttachment != null)
{
foreach (var file in originalMessage.ListFileAttachment)
{
msg.Attachments.Add(file);
}
}
return msg;
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Mail;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
MessageGmail mg = new MessageGmail();
mg.Subject = "test";
mg.Body = "test";
mg.ToList.Add("שם המייל", "כתובת המייל");
SendMail.SendEMail(mg);
}
}
}
פורסם במקור בפורום CODE613 ב29/08/2016 11:34 (+03:00)
תודה.
הקוד לא שולח לי.
פורסם במקור בפורום CODE613 ב26/08/2016 14:28 (+03:00)
אכן אתה צודק, בתחילה בדקתי בפקד הדפדפן של דוטנט וסקריפט הנ"ל עבד, אבל כעת בדקתי בכרום ובאקפלורר והסקריפט לא עובד, מוזר לא?
האפשרות לכתוב data:text/javscript קיימת רק בדפדפנים מבוססי כרומיום
פורסם במקור בפורום CODE613 ב16/10/2016 12:53 (+03:00)
מדועה האפשרות נעלמה?
פורסם במקור בפורום CODE613 ב01/09/2016 14:37 (+03:00)