제 코딩에 도움이 필요합니다. 이메일에 메시지를 보내려고하지만 버튼을 클릭하고 메시지를 보내려고하면 오류가 계속 발생합니다. 오류 라인을 제공C# 메일 보내기/메시지/SMTP 오류
msg.To.Add(new MailAddress(txtBoxToEmail.Text));
유지 여기 중지 프로젝트로 :
이using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
namespace CO6009DissertationV5
{
public partial class frmSendMsg : Form
{
public frmSendMsg()
{
InitializeComponent();
}
private void btnSend_Click(object sender, EventArgs e)
{
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 587;
client.EnableSsl = true;
System.Net.NetworkCredential userpassword = new System.Net.NetworkCredential();
userpassword.UserName = "[email protected]";
userpassword.Password = "password";
client.Credentials = userpassword;
MailMessage msg = new MailMessage("[email protected]", "[email protected]");
**msg.To.Add(new MailAddress(txtBoxToEmail.Text));**
msg.Body = "<b> Sender's Name: </b>" + txtBoxName.Text + "<p><b> Sender's E-mail: </b>" + txtBoxEmail.Text + "<p><b>Sender's Subject: </b>" + txtBoxSubject.Text + "<p><b>Sender's Message: </b>" + "<p>" + txtBoxMsg.Text;
msg.Subject = txtBoxSubject.Text;
msg.IsBodyHtml = true;
try
{
client.Send(msg);
lblMsgStatus.Text = "<p> Message Successfully Sent </p>";
}
catch (Exception ex)
{
lblMsgStatus.Text = "Send failed";
}
}
}
}
가장 큰 문제는이 선 것 같다 : 아래 코딩이
{ "매개 변수 '주소'는 빈 문자열 일 수 없습니다. \ r \ n 매개 변수 이름 : 주소 "}.
도움이 될만한 정보가 있으면 알려주세요. txtBoxToEmail.Text에 유효한 전자 메일 주소가
msg.To.Add(new MailAddress(txtBoxToEmail.Text));
없는 경우는, 시도 - 캐치와 코드를 포장하고 평가 예외 사항하시기 바랍니다 여전히 명확하지 않으면
여기에 사용자/비밀번호로 코드를 붙여 넣지 마십시오! – Pikoh
오류 메시지의 텍스트를 추가 할 수 있습니까? – Filburt
[Gmail을 통해 .NET으로 이메일 보내기] (http://stackoverflow.com/q/32260/205233)를 확인하고 다른 많은 질문이 이미 있습니다. 이전에 누군가가 귀하의 오류를 만났을 가능성이 큽니다. – Filburt