# Generate Email from Button

**URL:** <https://forum.inductiveautomation.com/t/generate-email-from-button/73669>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [May 12, 2023, 8:38pm UTC](https://forum.inductiveautomation.com/t/generate-email-from-button/73669 "2023-05-12T20:38:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 12, 2023, 8:38pm UTC](https://forum.inductiveautomation.com/t/generate-email-from-button/73669/1 "2023-05-12T20:38:39Z")

</div>

I am trying to generate an email from a button click. I am using the script editor in the event handler for said button. Below is the code I am using. I am receiving no error but also no emails when clicking the button. This is being done in Vision. Am I missing something in code or is this something I need to add or change in the gateway. We currently have other projects generating emails so I am guessing it is my code.

```auto
import system 
def onButtonClick(event): 
	# Get the email address of the recipient. 
	recipient = "email@email.com" 
	
	# Get the subject of the email. 
	subject = "This is the subject of the email." 
	
	# Get the body of the email. 
	body = "This is the body of the email." 
	
	# Get the default SMTP profile for the Gateway. 
	smtpProfile = system.net.getSMTPProfile() 
	# Send the email. 
	system.net.sendEmail(recipient, subject, body, smtpProfile)

```

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [May 12, 2023, 8:51pm UTC](https://forum.inductiveautomation.com/t/generate-email-from-button/73669/2 "2023-05-12T20:51:52Z")

</div>

> [@Chad\_Campbell](#):
>
> `getSMTPProfile() `

I cant find this in the documentation, and have you checked the logs from the gateway logs page?

I believe if you don't supply the parameter names then the order is important, i like to set things up like this example from the documentation.

```auto
body = "<HTML><BODY><H1>This is a big header</H1>"
body += "And this text is <font color='red'>red</font></BODY></HTML>"
recipients = ["bobsmith@mycompany.com", "1235558383@vtext.com", "sally@acme.org", "1235557272@vtext.com"]
cc_recipients = ["annejones@mycompany.com"]
smtp_server = "mySmtpServer"
system.net.sendEmail(smtpProfile=smtp_server, fromAddr="myemail@mycompany.com", subject="Here is the email!", body=body, html=1, to=recipients, cc=cc_recipients)

```

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 15, 2023, 1:09pm UTC](https://forum.inductiveautomation.com/t/generate-email-from-button/73669/3 "2023-05-15T13:09:35Z")

</div>

I tried a copy paste of your code and substituted the emails and the smtp server. When I click ok it accepts it in the designer I switch to preview mode and click the button and no error occurs in the designer. When I check the log files on the gateway I do not see anything as well. I can send myself a test email from the smpt server but for some reason it will not send from the button click in the vision designer.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 15, 2023, 4:33pm UTC](https://forum.inductiveautomation.com/t/generate-email-from-button/73669/4 "2023-05-15T16:33:41Z")

</div>

> [@Chad\_Campbell](#):
>
> I can send myself a test email from the smpt server

Is this from the smtp server itself, or is this from a [configured email profile](https://docs.inductiveautomation.com/display/DOC81/Email+Settings) on the gateway?

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 15, 2023, 5:34pm UTC](https://forum.inductiveautomation.com/t/generate-email-from-button/73669/5 "2023-05-15T17:34:43Z")

</div>

Yes, The Test is from the Gateway. Just not sure why when I use the smtp name in my code it does not send. an email.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 15, 2023, 5:55pm UTC](https://forum.inductiveautomation.com/t/generate-email-from-button/73669/6 "2023-05-15T17:55:02Z")

</div>

Is there any whitespace before or after the name? Just spitballing, but it is something I've come across before.

The smtp server itself (if you can see its logs, may also have some information)

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 15, 2023, 6:10pm UTC](https://forum.inductiveautomation.com/t/generate-email-from-button/73669/7 "2023-05-15T18:10:07Z")

</div>

There is no white space before, or after. This is currently working to send out emails for another project. I am trying to see if I can find something different between my project and the one that is functioning, but have not had any luck yet.
