Hello Ventuzians!
THE FORUMS ARE CLOSED!

Please join our discord server HERE!! << click me :D

We are shutting our Ventuz Forum, but don't worry, it will all be archived for you to search in if you have a query. From now on, please add all your comments, questions or observations into our Discord Server

Thanks for the great time - see you on discord!!
Dee, Karol, Daniel and the whoooole Product and Support team!

C sharp script help

Q and A about functionality and how to solve a special task for your application.

Moderator: Support

joysprod
Posts: 201
Joined: 20 Jan 2012, 12:24
Location: United Kingdom

Re: C sharp script help

Post by joysprod » 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;
}


}

User avatar
hgoodsir
Posts: 65
Joined: 05 Feb 2012, 16:17
Location: London
Contact:

Re: C sharp script help

Post by hgoodsir » 09 Nov 2012, 17:13

cool most excellent sir thanks :)

joysprod
Posts: 201
Joined: 20 Jan 2012, 12:24
Location: United Kingdom

Re: C sharp script help

Post by joysprod » 09 Nov 2012, 19:00

No Problems!

Also found this as a good example of how it works. They also have an excellent C# tutorial on their site...

http://www.blackwasp.co.uk/SendSmtpAsync.aspx

Regards

Peter

chriss0212
Posts: 666
Joined: 18 Jan 2012, 20:56
Location: wuppertal
Contact:

Re: C sharp script help

Post by chriss0212 » 10 Nov 2012, 12:04

hi chris, hi peter

just get it work one hour before :-)

thanks for all hints!

greetz

christian

User avatar
hgoodsir
Posts: 65
Joined: 05 Feb 2012, 16:17
Location: London
Contact:

Re: C sharp script help

Post by hgoodsir » 10 Nov 2012, 21:16

yes many thanks gentlemen :) brilliant scripting

Post Reply