The discharge sounds a bit like mucous from the problems you've been having with your digestive system. Hopefully it is not an infection. It is something that you should probably mention to your doctor.
To understand why flatulence occurs, one must look at the human body like it's a small factory. The gastrointestinal tract works as a unit. Once food reaches the stomach, all nutrients are broken down into smaller components (amino acids, fatty acids and glucose) before being absorbed in the small intestine. When food does not get absorbed into the intestinal wall, it cannot enter the bloodstream. Indigestible food and liquids are sent down the track where they reach the large colon (bowel) as waste for liquid reabsorption. It is there, in the large intestine, that the gases are formed.
Different bacteria in the bowel have a symbiotic relationship with the body (in some cases, they actually do more good than harm). The large colon contains a variety of digestive enzymes that feed off of unabsorbed nutrients. In the case of flatulence, foreign enzymes know as "gas enzymes" consume undigested nutrients by breaking their chemical bonds.
This process produces gases and the "end" result is, well we all know what the end result is. Enzymes burn food on a molecular level so passing gas is like exhaust fumes, and like all efficient factories, once an agent has been broken down, it produces gas.
Fermented food produces different types of fumes, some of which smell. Flatulence contains odorless gases, such as nitrogen, carbon dioxide, oxygen, and methane, but it also contains the "oh-so-nasty" hydrogen sulfide, which causes the smell.
How much odor is produced also depends on the types of food you eat and often on the types of medications you are taking. Vegetarians might fart as often as meat-eaters, but their "serenades" do not smell as much because vegetables produce less hydrogen sulfide. The more sulfur rich the foods you eat, the more your gas passing will have a foul odor because bacteria will generate sulfides and mercaptans as they break down the nutrients. Smelly gas is typically hydrogen sulphide which is produced by bacterial fermentation in the colon. This would be the sulfur smell of rotten eggs.
Flatulence occurs when a food does not break down completely in the stomach and small intestine. As a result the food makes it to the large intestine in an undigested state.
Unfortunately, healthy foods such as fruits, vegetables, oatmeal and legumes (beans and peas) are often the worst offenders. That's because these foods are high in soluble fiber. Soluble fiber dissolves in water forming a gelatinous substance in the bowel. Fiber has many health benefits, including keeping your digestive tract in good working order, regulating blood sugar and cholesterol levels, and helping prevent heart attacks and other heart problems. But it can also lead to the formation of gas. In the colon the bacteria thrive on the undigestible fiber. These bacteria are harmless but for those who have an intestinal gas or flatus problem, it is probably best to avoid or carefully test soluble fibers to see if they are contributing to intestinal gas.
On the other hand, insoluble fiber as found in wheat, rye, bran, and other grains does not dissolve in water. It is not used by intestinal colon bacteria as a food source, so these bacteria generally do not produce intestinal gas. Both soluble and insoluble fiber should be eaten on a daily basis.
By contrast, fats and proteins cause little gas. They are absorbed in the digestive tract before they get to the colon.
Sugars are known to create gas. Fructose is naturally present in onions, artichokes, pears, and wheat. It is also used as a sweetener in some soft drinks and fruit drinks. Sorbitol is a sugar found naturally in fruits, including apples, pears, peaches, and prunes. It is also used as an artificial sweetener in many dietetic foods and sugarfree candies and gums.
Foods that may cause gas include: Most beans, especially dried beans and peas, baked beans, soy beans, lima beans, vegetables, such as Cabbage; radishes; onions; broccoli; Brussels sprouts; cauliflower; cucumbers; sauerkraut; kohlrabi; asparagus, potatoes Fruits such as Prunes; apricots; apples; raisins; bananas. Carbonated beverages-
Soft drinks, fruit drinks, milk and milk products, such as cheese and ice cream. Packaged foods prepared with lactose, such as bread, cereal, and salad dressing. Foods containing sorbitol, such as dietetic foods and sugarfree candies and gums
Here are just some medical conditions that can cause smelly flatulence: Colitis (also ulcerative colitis ), Celiacs Disease, Crohn's Disease, Diabetes, IBS (Irritable Bowel Syndrome), IBD, AIDS / HIV (and related conditions), Malabsorptive Syndromes, Lactose Intolerance, Digestive disorders, Spastic colon, Menstrual periods, Vaginal flatulence.
Hope this helps you a bit!
Peace and Blessings
Look For The Good and Praise It!