发送一封带有文件的电子邮件,每次文件名都是当前时间
Send an email with a file and each time the file name is with the current time
我有一个任务要执行发送一个已经从数据库下载的文件
我将不得不通过电子邮件发送文件,并附上文件发送时的名称。
这个任务在集成服务中的执行顺序是什么
在ssis中使用文件系统任务和发送邮件任务。
毫无疑问,您应该首先创建您的文件系统任务并将其保存在您想要的位置。之后在控制流中使用“脚本任务”,您可以轻松发送它。您只需在“使用命名空间”块中添加这些来源:
“使用 System.Net.Mail;”
您需要在public main 方法中添加的代码应该是这样的:
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
string sSubject = [Your Subject Name String];
string sBody = [Your Body String];
string sEmailServer = [The Address of your Email Server];
string sEmailPort = [The Email Port];
string sEmailUser = [Your Email address];
string sEmailPassword = [Your Email Password];
string sEmailSendTo = [The Receiver Email];
string sEmailSendCC = [The CC Sender Email];
string sEmailSendFrom = [The Sender Email];
string sEmailSendFromName = [The Sender Name];
message.Priority = MailPriority.High;(Normal, Low, High).
MailAddress fromAddress = new MailAddress(sEmailSendFrom, sEmailSendFromName);
message.From = fromAddress;
string[] sEmailTo = Regex.Split(sEmailSendTo, ";");
string[] sEmailCC = Regex.Split(sEmailSendCC, ";");
int sEmailServerSMTP = int.Parse(sEmailPort);
smtpClient.Host = sEmailServer;
smtpClient.Port = sEmailServerSMTP;
smtpClient.EnableSsl = false;
System.Net.NetworkCredential myCredentials =
new System.Net.NetworkCredential(sEmailUser, sEmailPassword);
smtpClient.Credentials = myCredentials;
if (sEmailTo != null)
{
for (int i = 0; i < sEmailTo.Length; ++i)
{
if (sEmailTo[i] != null && sEmailTo[i] != "")
{
message.To.Add(sEmailTo[i]);
}
}
}
if (sEmailCC != null)
{
for (int i = 0; i < sEmailCC.Length; ++i)
{
if (sEmailCC[i] != null && sEmailCC[i] != "")
{
message.To.Add(sEmailCC[i]);
}
}
}
Attachment myAttachment = new Attachment([The path the file you saved]);
message.Attachments.Add(myAttachment);
message.Subject = sSubject;
message.IsBodyHtml = false;
message.Body = sBody;
smtpClient.Send(message);
我有一个任务要执行发送一个已经从数据库下载的文件 我将不得不通过电子邮件发送文件,并附上文件发送时的名称。
这个任务在集成服务中的执行顺序是什么 在ssis中使用文件系统任务和发送邮件任务。
毫无疑问,您应该首先创建您的文件系统任务并将其保存在您想要的位置。之后在控制流中使用“脚本任务”,您可以轻松发送它。您只需在“使用命名空间”块中添加这些来源: “使用 System.Net.Mail;”
您需要在public main 方法中添加的代码应该是这样的:
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
string sSubject = [Your Subject Name String];
string sBody = [Your Body String];
string sEmailServer = [The Address of your Email Server];
string sEmailPort = [The Email Port];
string sEmailUser = [Your Email address];
string sEmailPassword = [Your Email Password];
string sEmailSendTo = [The Receiver Email];
string sEmailSendCC = [The CC Sender Email];
string sEmailSendFrom = [The Sender Email];
string sEmailSendFromName = [The Sender Name];
message.Priority = MailPriority.High;(Normal, Low, High).
MailAddress fromAddress = new MailAddress(sEmailSendFrom, sEmailSendFromName);
message.From = fromAddress;
string[] sEmailTo = Regex.Split(sEmailSendTo, ";");
string[] sEmailCC = Regex.Split(sEmailSendCC, ";");
int sEmailServerSMTP = int.Parse(sEmailPort);
smtpClient.Host = sEmailServer;
smtpClient.Port = sEmailServerSMTP;
smtpClient.EnableSsl = false;
System.Net.NetworkCredential myCredentials =
new System.Net.NetworkCredential(sEmailUser, sEmailPassword);
smtpClient.Credentials = myCredentials;
if (sEmailTo != null)
{
for (int i = 0; i < sEmailTo.Length; ++i)
{
if (sEmailTo[i] != null && sEmailTo[i] != "")
{
message.To.Add(sEmailTo[i]);
}
}
}
if (sEmailCC != null)
{
for (int i = 0; i < sEmailCC.Length; ++i)
{
if (sEmailCC[i] != null && sEmailCC[i] != "")
{
message.To.Add(sEmailCC[i]);
}
}
}
Attachment myAttachment = new Attachment([The path the file you saved]);
message.Attachments.Add(myAttachment);
message.Subject = sSubject;
message.IsBodyHtml = false;
message.Body = sBody;
smtpClient.Send(message);