나는 잊어 버린 암호 기능을 제공하고자하는 Windows phone 앱을 만들고 있습니다. 앱이 비밀번호 기억 버튼을 누를 때 사용자의 저장된 이메일 ID로 이메일을 보냅니다. Windows 전화에서 사용할 수있는 smtp 클래스가 없으므로 앱에서 이메일 ID (및 비밀번호)를 받게 될 asp.net 웹 API를 만들고 싶습니다. 그 ID로 이메일을 보냅니다. 웹 서비스에 익숙하지 않고이 지식이 0 개임이 이 작업을 수행하는 방법을 안내하고 누구든지 코드를 제공 할 수 있으면 이처럼 사용할 수있는 웹 서비스가 있어야합니다.asp.net 웹 api를 통해 이메일을 보내는 방법
답변
다음은 사용할 수있는 이메일을 보내는 기능의 예입니다. 또한 ASP.NET에서 웹 서비스를 만드는 데 도움이되는 몇 가지 링크가 있습니다.
실제로이 경우 웹 서비스를 만들 필요는 없습니다 (권장 사항 임). 당신이 그가 .NET을 사용하기 위해이 example.com/sendemail.aspx?account=jack.smith 같은 & ID = 223232343
private static void SendEmail(string from, string from_name, string to, string cc, string bcc, string subject, string body, bool isHtml)
{
SmtpClient mailClient = new SmtpClient(Config.SmptSettings.Server);
mailClient.Credentials = new NetworkCredential(Config.SmptSettings.UserName, Config.SmptSettings.Password);
mailClient.Port = Config.SmptSettings.Port;
MailMessage message = new MailMessage();
if (!string.IsNullOrEmpty(from_name))
{
message.From = new MailAddress(from, from_name);
}
else
{
message.From = new MailAddress(Formatter.UnFormatSqlInput(from));
}
message.To.Add(new MailAddress(to));
if (!string.IsNullOrEmpty(cc))
{
message.CC.Add(cc);
}
if (!string.IsNullOrEmpty(bcc))
{
message.Bcc.Add(bcc);
}
message.Subject = subject;
message.Body = body;
message.IsBodyHtml = isHtml;
mailClient.EnableSsl = Config.SmptSettings.SSL;
mailClient.Send(message);
}
string random;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string s1 = string.Empty;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyCon"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select EmailId from tblEmail where EmailId='" + txtemail.Text + "'", con);
SqlDataReader dr =cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
s1 = dr.GetString(0);
}
}
dr.Close();
if (s1.Equals(txtemail.Text))
{
Session["Email"] = txtemail.Text;
try
{
Random rndm = new Random();
random = rndm.Next(99999).ToString();
MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add(new MailAddress(txtemail.Text));
message.Subject = " Hello... This is Your Serial No to change your password:";
message.Body = random.ToString();
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 587;//Gmail port number
client.UseDefaultCredentials = true;
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("[email protected]", "yourpassword");
client.Send(message);
SqlCommand cmd1 = new SqlCommand("insert into tblRandom values('" + txtemail.Text + "','" + random.ToString() + "')", con);
cmd1.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('Security Code Successfully Sent in Your Email Id')</script>");
Response.Redirect("~/anotherpage.aspx");
}
catch (Exception)
{
// Response.Write(ee.Message);
lblmsg.Text = "Please Enter Email-Id..";
lblmsg.Visible = true;
//MessageBox.Show("Please Enter Email-ID");
//Response.Write("<script>alert('Please Enter Email-ID')</script>");
}
}
else
{
lblmsg.Text = "Please Enter Correct Email-Id..";
lblmsg.Visible = true;
}
}
이 코드는 전자 메일로 보내기 For Forgot Password –
SQL 주입에 대해 들어 본 적이 있습니까? EmailId = ' "+ txtemail.Text +"' "대신에 SQLParameters를 사용해야합니다. – marco
## Call this function in your WebApi controller ##
private void sendEmailViaWebApi()
{
string subject = "Email Subject";
string body = "Email body";
string FromMail = "[email protected]";
string emailTo = "[email protected]";
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("mail.reckonbits.com.pk");
mail.From = new MailAddress(FromMail);
mail.To.Add(emailTo);
mail.Subject = subject;
mail.Body = body;
SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "your password");
SmtpServer.EnableSsl = false;
SmtpServer.Send(mail);
}
수신자 메일 제공자의 방화벽에 문제가 있습니까? 인증이 필요하지 않습니까? –
를 매개 변수를 전달하는 곳 당신은 신속하고 더러운 웹 양식을 만들 수 있습니다 핵심 사항으로, 현재 이메일 전송에 대한 지원은 없습니다. https://github.com/dotnet/corefx/issues/1006
대체 솔루션이 구현되었습니다 - MailKit :
은 GitHub의를 통해 .NET 코어에 대한 다음 문제를 참조하십시오 https://github.com/jstedfast/MailKit
- 1. infusionsoft api를 사용하여 이메일을 보내는 방법
- 2. xcopy를 통해 ASP.NET 웹 API를 배포하는 방법
- 3. PHP를 통해 그래픽으로 이메일을 보내는 방법
- 4. 서버 별칭 메일을 통해 이메일을 보내는 방법
- 5. Outlook을 통해 이메일을 보내는 방법 .asp
- 6. 아이폰으로 이메일을 통해 .caf 파일을 보내는 방법?
- 7. 델파이 7을 통해 Outlook을 통해 테이블을 통해 이메일을 보내는 방법
- 8. 웹 사이트에서 이메일을 보내는 현명한 방법
- 9. phpmailer를 사용하여 웹 서버에서 이메일을 보내는 방법
- 10. 내 웹 사이트에서 이메일을 보내는 방법
- 11. 이메일을 보내는 방법?
- 12. codeiginter에서 이메일을 보내는 방법
- 13. 이메일을 보내는 방법
- 14. 앱에서 이메일을 보내는 방법
- 15. PHP에서 이메일을 보내는 방법
- 16. grails에서 이메일을 보내는 방법
- 17. 자동으로 이메일을 보내는 방법
- 18. C에서 이메일을 보내는 방법
- 19. nodejs에서 이메일을 보내는 방법
- 20. 자체 API를 사용하여 이메일을 보내는 방법은 무엇입니까?
- 21. 이메일을 통해 활성화 코드를 보내는 방법은 무엇입니까? asp.net mvc2
- 22. PayPal API를 통해 일회성 결제를 보내는 방법
- 23. Getresponse에 API를 통해 리드를 보내는 방법
- 24. API를 통해 내 exe에 명령을 보내는 방법
- 25. Pl/sql에서 이메일을 보내는 방법
- 26. 접미사 : 사용자에게 이메일을 보내는 방법
- 27. 아이폰 코드에서 이메일을 보내는 방법
- 28. 웹 프로젝트를 위해 dataURL 그림을 이메일을 통해
- 29. 프레스코에서 이메일을 보내는 방법 4
- 30. GMail API를 사용하여 Google 그룹을 대신하여 이메일을 보내는 방법
웹 API이 적응되지 않습니다, 당신은 필요하지 않습니다 RESTful 서비스, 대신 WCF에서 확인하십시오. – glautrou