Re: C sharp script help
Posted: 09 Nov 2012, 16:42
using System;
using Ventuz.Kernel;
using System.Net;
using System.Net.Mail;
using System.Web;
public class Script : ScriptBase, System.IDisposable
{
// This member is used by the Validate() method to indicate
// whether the Generate() method should return true or false
// during its next execution.
private bool changed;
// This Method is called if the component is loaded/created.
public Script()
{
// Note: Accessing input or output properties from this method
// will have no effect as they have not been allocated yet.
}
// This Method is called if the component is unloaded/disposed
public virtual void Dispose()
{
}
// This Method is called if an input property has changed its value
public override void Validate()
{
}
public override bool Generate()
{
if (changed)
{
changed = false;
return true;
}
return false;
}
// This Method is called if the function/method SendNow is invoked by the user or a bound event.
// Return true, if this component has to be revalidated!
public bool OnSendNow(int arg)
{string SendersAddress = this.YourEmail;
string ReceiversAddress = this.SendToEmail;
string SendersPassword = this.EmailPassword;
string subject = this.Subject;
string body = this.EmailBody;
try
{
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp server";
smtp.Port = 587;
smtp.EnableSsl = false; //or true
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(SendersAddress, SendersPassword);
smtp.Timeout = 30000;
MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body);
//Disable these 3 lines if no attachments
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(EmailAttachment);
message.Attachments.Add(attachment);
//Above 3
smtp.SendAsync(message, ""); // no error checking is carried out. Need to look at the MSDN site for more details
this.MessageSent = ("Message Sent Successfully");
Exception = "";// Clear the exception if succesful send
}
catch (Exception ex)
{
this.Exception = (ex.Message);
}
changed = true;
return false;
}
}
using Ventuz.Kernel;
using System.Net;
using System.Net.Mail;
using System.Web;
public class Script : ScriptBase, System.IDisposable
{
// This member is used by the Validate() method to indicate
// whether the Generate() method should return true or false
// during its next execution.
private bool changed;
// This Method is called if the component is loaded/created.
public Script()
{
// Note: Accessing input or output properties from this method
// will have no effect as they have not been allocated yet.
}
// This Method is called if the component is unloaded/disposed
public virtual void Dispose()
{
}
// This Method is called if an input property has changed its value
public override void Validate()
{
}
public override bool Generate()
{
if (changed)
{
changed = false;
return true;
}
return false;
}
// This Method is called if the function/method SendNow is invoked by the user or a bound event.
// Return true, if this component has to be revalidated!
public bool OnSendNow(int arg)
{string SendersAddress = this.YourEmail;
string ReceiversAddress = this.SendToEmail;
string SendersPassword = this.EmailPassword;
string subject = this.Subject;
string body = this.EmailBody;
try
{
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp server";
smtp.Port = 587;
smtp.EnableSsl = false; //or true
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(SendersAddress, SendersPassword);
smtp.Timeout = 30000;
MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body);
//Disable these 3 lines if no attachments
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(EmailAttachment);
message.Attachments.Add(attachment);
//Above 3
smtp.SendAsync(message, ""); // no error checking is carried out. Need to look at the MSDN site for more details
this.MessageSent = ("Message Sent Successfully");
Exception = "";// Clear the exception if succesful send
}
catch (Exception ex)
{
this.Exception = (ex.Message);
}
changed = true;
return false;
}
}