PDA

View Full Version : ASP .NET (C#) sending mail


Tartampion
09-23-2003, 04:22 PM
I need to know if it is possible to include links in code-generated e-mails. I have a aspx page that send customers confirmation of their subscription to a site. I need to know how to include a link in the mail tha will enable them to go to the site from the email.

It's done in c#.
I use these namespaces:

using System.Web.Mail;
using System.Text;
using System.ServiceProcess;

// This is the code : it actually works fine

MailMessage msg = new MailMessage();
msg.From = strAddressFRrom;
msg.To = strAdresseTo;
msg.Subject = strSubject;
// sb is a string builder object which is filled before the message is sent ( it is not copied here to keep code short )
msg.Body = sb.ToString();
msg.Priority = System.Web.Mail.MailPriority.Normal;

SmtpMail.SmtpServer = "127.0.0.1";

SmtpMail.Send( msg );

i tried including many different html structures in the StringBuilder object. I tried with only a href tag, and even with a whole html document. None worked. If you have any idea how to do this, your input qould be gratly appreciated...
Thanks

dvanniel
02-03-2004, 02:29 PM
Tartampion,

I don't know if you you the answer yet. I guess so, 'cause it's been a while since you posted it ;)

But it's never too late to say thanks for the code ! I was looking for a few lines that would let me send mail from an asp.net page and this does the trick perfectly. So thanks again.

The code I use to send HTML (including links, et al) is the follwing;

msg.BodyFormat = MailFormat.Html;
msg.Body = "<HTML><BODY><FONT FACE= Arial SIZE = 2 ><A HREF = HTTP://WWW.LINTWORM.TK >Link</A></FONT></BODY></HTML>";

If you insert this at the appropriate place in the code you listed in your post you should be able to send links, even whole HTML documents! :)
Just be sure to leave out any quotes besides the ones that mark the string. If you put them in it will leave your dev environment confused and not very eager to compile.

It SHOULD be working for you because i do not know if VS.Net 2003 is up to it...i'm coding in VS.Net Whidbey which has some extra (new) classes, which are *very* nice btw.

dENNIS