Sending Email with attachment

9 years 4 months ago - 9 years 3 months ago #1985 by hjfabius
hi,
I'm building my simple home alarm. :huh:
I was able to send an email notification if movement is captured by a PIR sensor. :woohoo:

I would like to add to the email a picture grabbed by the raspberry camera. :silly:
Any suggestion how to do it with EmailHelper?
Should I integrate a different SMTP client?

Thanks
Hjfabius

Please Log in or Create an account to join the conversation.

9 years 3 months ago #1996 by bit
Replied by bit on topic Sending Email with attachment
EmailHelper don't seems to have capability to send attachment, but that's possible in C++. you could suggest developer to add this feature in next releases.

PS: take a look at this post, it could be interesting for you
iot-playground.com/forum/suggestion-box/...id-ip-cameras/unread

I'm sorry for my poor english.

Please Log in or Create an account to join the conversation.

9 years 3 months ago - 9 years 3 months ago #2000 by hjfabius
Finally I was able to manage it via C#- I believe the code could be easily integrated in the EmailHelper adding a new optional parameter.

try 
{ 
	Console.WriteLine("Email Sender - Standard");   
   
    /*Configuration of the SMTP Client*/
	System.Net.Mail.SmtpClient  	client 		= new System.Net.Mail.SmtpClient("smtp.gmail.com", 587); 
	client.Credentials = new System.Net.NetworkCredential("username", "password"); 
	client.EnableSsl = true; 
	client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; 
   
	/*Configuration of the EMAIL object*/
	System.Net.Mail.MailAddress 	fromMail 	= new System.Net.Mail.MailAddress("email", "Easy Iot Server",  System.Text.Encoding.UTF8); 
	System.Net.Mail.MailAddress 	toMail 		= new System.Net.Mail.MailAddress("email"); 
	System.Net.Mail.MailMessage 	message 	= new System.Net.Mail.MailMessage(fromMail, toMail); 
	message.Subject = "test message 2"; 
	message.SubjectEncoding = System.Text.Encoding.UTF8;   
	message.Body = "This is a test e-mail message sent by an application. "; 
	message.BodyEncoding =  System.Text.Encoding.UTF8; 


	/* Opening of the web request stream to get the image from the camera */
	string strFile = "http://192.168.0.14/cam.jpg"; 
	string strLocalFile = "/tmp/cam.jpg"; 
	System.Net.WebRequest objWebRequest = System.Net.WebRequest.Create(strFile); 
	System.Net.WebResponse objWebResponse = objWebRequest.GetResponse();		 
	System.Net.Mail.Attachment objAttachment = new System.Net.Mail.Attachment(objWebResponse.GetResponseStream(), strLocalFile); 
	
	/* Attach the image to the email*/
	message.Attachments.Add(objAttachment);   




	/* Sending the message */
	client.Send(message); 
	Console.WriteLine("Message Sent.");   
} 
catch (Exception e) 
{ 
	Console.WriteLine("An Exception occurred: '{0}'", e); 
} 
The following user(s) said Thank You: bit

Please Log in or Create an account to join the conversation.

9 years 3 months ago #2002 by bit
Replied by bit on topic Sending Email with attachment
thanks for share

I'm sorry for my poor english.

Please Log in or Create an account to join the conversation.

9 years 3 months ago #2060 by skywatch
That is a cool feature and it would be good to have it in EIoT .

Please Log in or Create an account to join the conversation.

Time to create page: 0.300 seconds

Forum latest

  • No posts to display.