制作表格由谷歌服务器发送 [英] Make a form send by google server
本文介绍了制作表格由谷歌服务器发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用发送到我的Gmail帐户的三个元素来获取这个简单的表单。我在互联网上看了很多,但却找不到怎么做。你有谁可以帮我吗?
这是我的HTML代码,格式为:
I am trying to get this simple form with three elements sent to my gmail account. I have read a lot on internet, but can not find out how to do it. Can anyone of you help me with it?
Here is my HTML-code with the form:
<form action="Kontakt.aspx.cs" method="post">
<fieldset id="fieldset"><legend>Contact</legend>
<label for="name">Name:</label>
<input type="text" name="name" required placeholder="Name" />
<label for="email">Email:</label>
<input type="email" name="email" required placeholder="email@eksempel.com" />
<label for="message">Message:</label>
<textarea name="message" required placeholder="Message"></textarea>
<input type="submit" value="Send" />
<input type="reset" value="Empty" />
</fieldset>
</form>
我的c#-code:
My c#-code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Net.Mail;
using System.Net.Mime;
namespace Magikeren.Script
{
public partial class KontaktMail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
string Navn = Request["name"];
string Email = Request["email"];
string Melding = Request["message"];
MailAddress fromAddress = new MailAddress(Email, Navn);
message.From = fromAddress;
message.To.Add("myemail@gmail.com");
message.Subject = "Subject";
message.IsBodyHtml = true;
message.Body = Melding;
}
}
}
我的网页配置:
And my Web config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network
host="smtp.gmail.com"
port="465"
defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
</configuration>
推荐答案
有很多关于如何在互联网上发送邮件的示例,例如使用ASP.NET和C#发送邮件/联系表单 [ ^ ]。
There are lots of samples of how to send mail messages around the internet, for example Send Mail / Contact Form using ASP.NET and C#[^].
protected void Button1_Click(object sender, EventArgs e)
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress("Your@mail.in", "Sender name");
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 587;
message.From = fromAddress;
message.To.Add("Sent@mail.in");
message.Subject = "Subject" ;
message.IsBodyHtml = false;
message.Body = "Message ";
smtpClient.Credentials = new System.Net.NetworkCredential("Your@mail.in", "Passwprd");
smtpClient.EnableSsl = true;
smtpClient.Send(message);
Label1.Text = "Request successfully sent.";
}
catch (Exception)
{
Label1.Text = "Send RequestFailed. Try Again" ;
}
}
这篇关于制作表格由谷歌服务器发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文