Bạn muốn gởi mail dạng PlainText hay Html, hãy sử dụng đoạn mã
Còn nếu muốn chèn hình ảnh vào email thì làm như sau:
The LinkedResource class is the last, and least used main class. It is mainly used for creating embedded images. To create an embedded image you will need to first create a Html formatted AlternateView. Within that alternate view you create an tag, that points to the ContentId (CID) of the LinkedResource. You then create a LinkedResource object and add it to the AlternateView's LinkedResources collection.
Tùy chỉnh trong Web.Config
//first we create the Plain Text part AlternateView plainView = AlternateView.CreateAlternateViewFromString("This is my plain text content, viewable by those clients that don't support html", null, "text/plain"); //then we create the Html part AlternateView htmlView = AlternateView.CreateAlternateViewFromString("this is bold text, and viewable by those mail clients that support html", null, "text/html"); mail.AlternateViews.Add(plainView); mail.AlternateViews.Add(htmlView);Chú ý: Bạn add kiểu nhìn nào thì nó sẽ hiển thị kiểu nhìn đó. Lấy giá trị sau cùng.
Còn nếu muốn chèn hình ảnh vào email thì làm như sau:
//To embed images, we need to use the prefix 'cid' in the img src value //the cid value will map to the Content-Id of a Linked resource. //thusGiải thích: (Xin để tiếng Anh cho dễ hiểu)will map to a LinkedResource with a ContentId of 'myPicture' Alternateview view = Alternateview.CreateAlternateviewFromString("Here is an embedded image.
", null, "text/html"); //Create the LinkedResource LinkedResource myPicture = new LinkedResource( "c:\\temp\\Picture.gif" ); logo.ContentId = "myPicture"; //Add the LinkedResource to the view htmlview.LinkedResources.Add(myPicture); mail.Alternateviews.Add(view);
The LinkedResource class is the last, and least used main class. It is mainly used for creating embedded images. To create an embedded image you will need to first create a Html formatted AlternateView. Within that alternate view you create an tag, that points to the ContentId (CID) of the LinkedResource. You then create a LinkedResource object and add it to the AlternateView's LinkedResources collection.
Tùy chỉnh trong Web.Config
Nhận xét
Đăng nhận xét