2013-01-16 3 views
1

기본 이메일을 폴더로 보내려고합니다. 전자 메일을 받았지만 본문이 완전히 누락되었습니다. 기본 이메일을 폴더로 보내려고합니다

private void MailReport() 
{ 

    string to = "[email protected]"; 
    string From = "[email protected]"; 
    string subject = "Report"; 
    **string Body = "Dear sir ,<br> Plz Check d Attachment <br><br>";** 


    bool send = sendMail(to, From, subject, Body); 

    if (send == true) 
    { 
     string CloseWindow = "alert('Mail Sent Successfully!');"; 
     ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", CloseWindow, true); 
    } 
    else 
    { 
     string CloseWindow = "alert('Problem in Sending mail...try later!');"; 
     ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", CloseWindow, true); 
    } 
} 

public bool sendMail(string to, string from, string subject, string body) 
{ 
    bool k = false; 
    try 
    { 
     MailMessage msg = new MailMessage(from, to); 
     msg.Subject = subject; 

     AlternateView view; 
     SmtpClient client; 
     StringBuilder msgText = new StringBuilder(); 
     view = AlternateView.CreateAlternateViewFromString(msgText.ToString(), null, "text/html"); 
     msg.AlternateViews.Add(view); 


     msgText.Append("<body><br></body></html> <br><br><br> " + body); 

     client = new SmtpClient(); 
     client.Host = "staging.itmaniax.co.za"; 
     client.Send(msg); 

     k = true; 

    } 
    catch (Exception exe) 
    { 
     Console.WriteLine(exe.ToString()); 
    } 
    return k; 


} 

<system.net> 
<mailSettings > 
    <smtp deliveryMethod="specifiedPickupDirectory" from="[email protected]"> 
    <network host="staging.itmaniax.co.za"/> 
    <specifiedPickupDirectory pickupDirectoryLocation="C:\testdump\emaildump\"/> 
    </smtp> 
</mailSettings> 

나는 그것이 비주얼 스튜디오 2008과 수행으로 문제를 느끼는 것은 몸과 HTML로 자리 잡고 있습니다. 조언이 있으십니까?

+1

'sendMail' 메소드에 도달 할 때 중단 점을 넣고'body'에 값이 있는지 확인하십시오. 'msgText'의 HTML은 완전히 잘못되었습니다. 나는 HTML을 없애고, 그냥 몸에 덤프하고 OK를 통해 볼 수 있는지 확인합니다. – Arran

답변

1

다음과 같이 시도해 볼 수 있습니다.

protected void SendMail() 
{ 
    // Gmail Address from where you send the mail 
    var fromAddress = "[email protected]"; 
    // any address where the email will be sending 
    var toAddress = YourEmail.Text.ToString(); 
    //Password of your gmail address 
    const string fromPassword = "Password"; 
    // Passing the values and make a email formate to display 
    string subject = YourSubject.Text.ToString(); 
    string body = "From: " + YourName.Text + "\n"; 
    body += "Email: " + YourEmail.Text + "\n"; 
    body += "Subject: " + YourSubject.Text + "\n"; 
    body += "Question: \n" + Comments.Text + "\n"; 
    // smtp settings 
    var smtp = new System.Net.Mail.SmtpClient(); 
    { 
     smtp.Host = "smtp.gmail.com"; 
     smtp.Port = 587; 
     smtp.EnableSsl = true; 
     smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; 
     smtp.Credentials = new NetworkCredential(fromAddress, fromPassword); 
     smtp.Timeout = 20000; 
    } 
    // Passing values to smtp object 
    smtp.Send(fromAddress, toAddress, subject, body); 
} 

protected void Button1_Click(object sender, EventArgs e) 
{ 
    try 
    { 
     //here on button click what will done 
     SendMail(); 
     DisplayMessage.Text = "Your Comments after sending the mail"; 
     DisplayMessage.Visible = true; 
     YourSubject.Text = ""; 
     YourEmail.Text = ""; 
     YourName.Text = ""; 
     Comments.Text = ""; 
    } 
    catch (Exception) { } 
} 

자세한 내용은 나는이 당신에게 도움이되기를 바랍니다 Send Mail/Contact Form using ASP.NET and C#

확인합니다.

1

당신이 누락 된 것 같습니다 :

MailMessage msg = new MailMessage(from, to); 
msg.Subject = subject; 

msg.Body = body; <--- try adding this and see what happens. 

msg.Body 속성이 예제에서, 나는 그것이 본문 텍스트를 전송하지 않습니다 그 이유는 추측 비어 있습니다.

관련 문제