-1
私はフォームを通じてメールを送信するコードを作成しました。 n電子メールを送信していません
protected void SendMail()
{
string firstName = fName.Text.ToString();
string lastName = lName.Text.ToString();
string event = eventName.Text.ToString();
string phoneNum = phone.Text.ToString();
string pass1 = pass.Text.ToString();
string address1=address.Text.ToString();
string email = gmail.Text.ToString();
string body = "From: " + firstName+" " +lastName+ "\n";
string subject = "title " + event;
body += "Email: " + email + "\n";
body += "Event: " + event + "\n";
body += "Phone Number: " + phoneNum + "\n";
body += "Password: " + pass1 + "\n";
body += "Event address: " + address1 + "\n";
// smtp settings
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add("[email protected]");
mail.From = new MailAddress("[email protected]", "title", System.Text.Encoding.UTF8);
mail.Subject = "title";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = body;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = System.Net.Mail.MailPriority.High;
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
try
{
client.Send(mail);
Response.Redirect("sadasd.aspx");
}
catch (Exception ex)
{
}
}
私の問題は、電子メールは大混乱であると\n
が動作していないということです。これが私の方法です。どうすれば回線をダウンできますか?なぜそれは働いていないのですか?
「\ n」ではなく「Environmen.NewLine」を使用できます。改行文字はオペレーティングシステムに依存します。 –
'\ n'を' + Environment.NewLine();に置き換えてください。 – MethodMan
メッセージの本文はhtmlです。してみてください
– Marusyk