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

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

C sharp script help

Post by hgoodsir » 24 Oct 2012, 16:05

hi all,

I have been looking on line and found a c script for emailing via gmail a file but not sure how to integrate into scene, so I can email snap shots using the script.

using System;
using System.Windows.Forms;
using System.Net.Mail;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("your_email_address@gmail.com");
mail.To.Add("to_address");
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";

System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("your attachment file");
mail.Attachments.Add(attachment);

SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;

SmtpServer.Send(mail);
MessageBox.Show("mail Send");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}

User avatar
Chris
Posts: 108
Joined: 14 Aug 2012, 09:10
Location: UK

Re: C sharp script help

Post by Chris » 31 Oct 2012, 20:51

Hi Hashim,

I'm still in the early stage of C# but ive been having a go at this :)

I think i found the post that you referenced your code from and i couldn't get it to work in visual studio, so i picked up another bit of code and had a go with that ;)
I have successfully sent email from visual studio with this code so have transferred it in to Ventuz to do some testing.

after some hours of compiling errors in Ventuz i have now got a code that is returning zero compile errors in the script node (getting there ;) )

But.....and its a big but.....i still haven't been able to send a test email from Ventuz......

So I too am now wondering if anyone can point out where this script is going wrong in order to achieve said task :)
See attached file :)

If theres any prob with attachment, heres the code so far.....
added to Validate()......

inputs added to script node:
strings: YourEmail, SendToEmail, EmailPassword, Subject, EmailBody
Bool: Update

Outputs added to script node:
Strings: Exception, MessageSent

using System.Net;
using System.Net.Mail;
using System.Web;

{
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.Gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(SendersAddress, SendersPassword);
smtp.Timeout = 30000;


MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body);

smtp.Send(message);
this.MessageSent = ("Message Sent Successfully");

}
catch (Exception ex)
{
this.Exception = (ex.Message);
}

changed = true;

}

hopefully we can get this sorted :) ;)

Cheers
Chris

p.s didn't get attachement working either, which i know is what you want the script for.......so any ideas on that would be awesome :)

User avatar
Chris
Posts: 108
Joined: 14 Aug 2012, 09:10
Location: UK

Re: C sharp script help

Post by Chris » 31 Oct 2012, 20:53

oooops.....forgot file :roll:
Attachments
GmailFromVentuz.vza
(6.96 KiB) Downloaded 622 times

User avatar
Daniel Willer
Posts: 309
Joined: 06 Jan 2012, 18:12

Re: C sharp script help

Post by Daniel Willer » 01 Nov 2012, 16:36

It works fine for me just paste your code in a method created via the CustomModel.


Cherio!

User avatar
Chris
Posts: 108
Joined: 14 Aug 2012, 09:10
Location: UK

Re: C sharp script help

Post by Chris » 01 Nov 2012, 20:40

It works! excellent! cheers Daniel (got your email ;) )

now i will have a look at the attach file option and come back with a working answer....hopefully ;)


chris

User avatar
Chris
Posts: 108
Joined: 14 Aug 2012, 09:10
Location: UK

Re: C sharp script help

Post by Chris » 02 Nov 2012, 06:43

add this just before .......smtp.send(message);

System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(@"C:\Users\the file URL goes here");
message.Attachments.Add(attachment);

:)

solved.....:)

Chris

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

Re: C sharp script help

Post by hgoodsir » 02 Nov 2012, 14:51

This is excellent Chris thanks for this :)

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

Re: C sharp script help

Post by joysprod » 02 Nov 2012, 18:38

Nice bit of scripting which as a new C# user I could just about understand.

Does your render stall when sending the email? How can this be avoided?

Regards

Peter

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

Re: C sharp script help

Post by joysprod » 07 Nov 2012, 15:56

Answering my own question...

Simple really, use sendasync to send the mail!

Peter

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, 00:16

cool iv'e tried to understand the sendasync, looking at link
http://msdn.microsoft.com/en-us/library ... async.aspx
but i have no idea how to add to script any help :)

Post Reply