-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentMail.cs
More file actions
77 lines (67 loc) · 2.44 KB
/
SentMail.cs
File metadata and controls
77 lines (67 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.ComponentModel;
using System.Net.Mail;
using System.Text;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class SentMail : MonoBehaviour
{
//https://www.youtube.com/watch?v=lk5dhDzfzsU
private SmtpClient mSmtpServer;
// Start is called before the first frame update
void Start()
{
// Command-line argument must be the SMTP host.
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.Credentials = new System.Net.NetworkCredential(
"posetmage@gmail.com",
"aaaaaaaaa");
client.EnableSsl = true;
// Specify the email sender.
// Create a mailing address that includes a UTF8 character
// in the display name.
MailAddress from = new MailAddress(
"youremail@gmail.com",
"Your Name",
System.Text.Encoding.UTF8);
// Set destinations for the email message.
MailAddress to = new MailAddress("posetmage@outlook.com");
// Specify the message content.
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test email message sent by an application. ";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = "test message 1";
message.SubjectEncoding = System.Text.Encoding.UTF8;
// Set the method that is called back when the send operation ends.
client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
// The userState can be any object that allows your callback
// method to identify this send operation.
// For this example, the userToken is a string constant.
string userState = "test message1";
client.SendAsync(message, userState);
}
// Update is called once per frame
void Update()
{
}
private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
{
// Get the unique identifier for this asynchronous operation.
string token = (string)e.UserState;
if (e.Cancelled)
{
Debug.Log("Send canceled " + token);
}
if (e.Error != null)
{
Debug.Log("[ " + token + " ] " + " " + e.Error.ToString());
}
else
{
Debug.Log("Message sent.");
}
}
}