나는 해결책을 찾고 있었지만 잘 모르겠다. C#에서 전자 메일 클라이언트를 만들고 있습니다. 나는 C#으로 돌아갈 수 있지만 때로는 구문에 매료된다.문자열과 Int에 If 문을 지정하는 경우
내 문제. 이메일의 사용자 입력을 기반으로 smtpclient 설정을 지정하려고합니다. 줄 53 (할당되지 않은 지역 변수 사용)에서 오류가 발생했습니다. 여기
smtpclient smm = new smtpclient(s, p);
내 코드입니다 :
private void Send_Click(object sender, EventArgs e)
{
//Set the login info for the email
NetworkCredential nc = new NetworkCredential(Euser.Text, Epass.Text);
MailMessage msg = new MailMessage();
msg.To.Add(Toemail.Text);
msg.From = new MailAddress(Euser.Text);
msg.Subject = Subemail.Text;
msg.Body = body.Text;
string s;
int p;
if (Euser.Text.Contains("@gmail.com") == true)
{
s = "smtp.gmail.com";
p = 587;
}
if (Euser.Text.Contains("@yahoo.com") == true)
{
s = "smtp.mail.yahoo.com";
p = 995;
}
if (Euser.Text.Contains("@live.com") == true)
{
s = "smtp.live.com";
p = 587;
}
SmtpClient smm = new SmtpClient(s, p);
smm.Credentials = nc;
smm.EnableSsl = true;
try
{
smm.Send(msg);
MessageBox.Show("Emails Sent Successfully");
}
catch (Exception ex)
{
MessageBox.Show("There was an error sending your emails");
}
정확히 내가 잘못 뭐하는 거지
? 이를 위해 메소드를 작성해야합니까? 어떤 도움을 주셔서 감사합니다.
예, 당신은's'와'p'의 값이 무엇이라고 기대합니까? 그러한 조건 중 어느 것도 사실이 아닌 경우? 어떤 값도 할당하지 않을 것이고, C#에서는 명확하게 할당되지 않은 지역 변수를 읽을 수 없습니다. –
죄송합니다. 방금 게시물을 업데이트했습니다. 오류는 할당되지 않은 로컬 변수입니다. – RynoZ