在c#中正确安排电子邮件的正文 [英] Arrange body of the email properly in c#

查看:145
本文介绍了在c#中正确安排电子邮件的正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,





现在我想用smtp服务器发送电子邮件。我成功完成了这件事。在这里,我的问题是如何用线间适当的空间改变我的图像体。现在我发送的消息主题看起来像亲爱的用户,感谢您在我的网站注册,感谢和问候,Dhinesh kumar V 。但我需要像



尊敬的用户,





感谢您的注册在我的网站上。







谢谢和问候,



Dhineshkumar V







所有回复都是欢迎。

Hi all,


Now i wanna send email by using smtp server. Successfully i done that. Here my problem is how to change my body of the image with proper space between lines. Now my delivered message subject looking like Dear User, Thanks for register in my site,Thanks and Regards, Dhinesh kumar V. But am need like

Dear User,


Thanks for register in my site.



Thanks and Regards,

Dhineshkumar V



All replies are Welcome.

推荐答案

试试这个...... :)



try this...:)

mail.Body = "Name: " + newInfo.ContactPerson + Environment.NewLine
                                + "Phone: " + newInfo.Phone + Environment.NewLine
                                + "Fax: " + newInfo.Fax + Environment.NewLine
                                + "Email: " + newInfo.Email + Environment.NewLine
                                + "Address: " + newInfo.Address + Environment.NewLine
                                + "Remarks: " + newInfo.Notes + Environment.NewLine
                                + "Giftwrap: " + rbGiftWrap.SelectedValue + Environment.NewLine
                                + "Giftwrap Instructions: " + newInfo.Instructions + Environment.NewLine + Environment.NewLine
                                + "Details: " + Environment.NewLine
                                + mailDetails;


这就是我要做的:



This is what I would do:

private void SendRegistrationMail()
{
    StringBuilder sb = new StringBuilder();

    sb.AppendLine("Dear User,");
    sb.AppendLine("");
    sb.AppendLine("Thanks for register in my site.");
    sb.AppendLine("");
    sb.AppendLine("Thanks and Regards,");
    sb.AppendLine("Dhineshkumar V");

    MailMessage message = new MailMessage();
    message.To.Add("[USER EMAIL]");
    message.Subject = "Thank you for registering";
    message.From = new MailAddress("[MY_OWN_EMAIL]");
    message.Body = (sb.ToString());
    message.IsBodyHtml = true;  //Set true to send HTML mails, false to send TEXT mails

    SmtpClient smtp = new SmtpClient("[MY_SMTP_SERVER_NAME]");

    smtp.Port = 80; //Or whatever
    smtp.EnableSsl = false; //True if your server requires SSL

    string smtpUserName = ""; //If necessary
    string smtpPassword = ""; //If necessary

    if (smtpUserName != "" && smtpPassword != "")
        smtp.Credentials = new NetworkCredential(smtpUserName, smtpPassword);

    try
    {
        smtp.Send(message);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message + Environment.NewLine + Environment.NewLine + ex.StackTrace,
                        "Couldn't send email!", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}


这篇关于在c#中正确安排电子邮件的正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆