开发者

How to set from when sending email via smtp server with using microsoft c#

How to set "from" when sendin email via smtp server with using microsoft c#

if you look this image you will understand what i mean

i use the code below for sending emails

How to set from when sending email via smtp server with using microsoft c#

MailMessage mail = new MailMessage();
                  开发者_开发知识库  mail.To.Add(srUserEmail);

                    string srBody = "bla bla bla";
 mail.From = new MailAddress("PokemonCraft.Announcement@pokemoncraft.com");
                        mail.Subject = "bla bla bla";
     mail.Body = srBody;
                    mail.IsBodyHtml = true;

                    SmtpClient smtp = new SmtpClient();

                    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                    smtp.UseDefaultCredentials = true;
                    smtp.Host = "xxx.xx.xx.xx";
                    smtp.Port = xxx;


                    smtp.Send(mail);


Pass a second argument to the MailAddress constructor:

mail.From = new MailAddress("Announcement@pokemoncraft.com", "Some Display Name")


Format your email address like this:

mail.From = new MailAddress("PokemonCraft <PokemonCraft.Announcement@pokemoncraft.com>");

The MailAddress object should recognize that the part inside <> tags is an email address, whereas the part preceding that is the name of the person or business sending the email.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜